Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1731892

Re: [PATCH V2 1/4] kthread: add a mechanism to store cgroup info

From Tejun Heo <tj@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH V2 1/4] kthread: add a mechanism to store cgroup info
Date 2017-09-13 23:40 +0200
Message-ID <upny2-4iM-17@gated-at.bofh.it> (permalink)
References <upn4Z-47u-3@gated-at.bofh.it> <upn50-47u-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Hello,

On Wed, Sep 13, 2017 at 02:01:26PM -0700, Shaohua Li wrote:
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 26db528..3107eee 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -20,7 +20,6 @@
>  #include <linux/freezer.h>
>  #include <linux/ptrace.h>
>  #include <linux/uaccess.h>
> -#include <linux/cgroup.h>
>  #include <trace/events/sched.h>
>  
>  static DEFINE_SPINLOCK(kthread_create_lock);
> @@ -47,6 +46,7 @@ struct kthread {
>  	void *data;
>  	struct completion parked;
>  	struct completion exited;

maybe #ifdef CONFIG_CGROUPS?

> +	struct cgroup_subsys_state *blkcg_css;
>  };
...
> +void kthread_associate_blkcg(struct cgroup_subsys_state *css)
> +{
> +	struct kthread *kthread;
> +
> +	if (!(current->flags & PF_KTHREAD) || !current->set_child_tid)
> +		return;
> +	kthread = to_kthread(current);
> +	if (css) {
> +		css_get(css);
> +		kthread->blkcg_css = css;
> +	} else if (kthread->blkcg_css) {
> +		css_put(kthread->blkcg_css);
> +		kthread->blkcg_css = NULL;
> +	}
> +}
> +EXPORT_SYMBOL(kthread_associate_blkcg);

Maybe doing sth like the following is less error-prone?

kthread_associate_blkcg(@css)
{
	if (current's kthread->blkcg_css)
		put kthread->blkcg_css and set it to NULL;
	if (@css)
		get @css and set kthread->blkcg;
}

Thanks.

-- 
tejun

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH V2 1/4] kthread: add a mechanism to store cgroup info Shaohua Li <shli@kernel.org> - 2017-09-13 23:10 +0200
  Re: [PATCH V2 1/4] kthread: add a mechanism to store cgroup info Tejun Heo <tj@kernel.org> - 2017-09-13 23:40 +0200
    Re: [PATCH V2 1/4] kthread: add a mechanism to store cgroup info Tejun Heo <tj@kernel.org> - 2017-09-13 23:50 +0200
    Re: [PATCH V2 1/4] kthread: add a mechanism to store cgroup info Shaohua Li <shli@kernel.org> - 2017-09-14 00:40 +0200

csiph-web