From: Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: "Frederic Weisbecker"
<fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Cgroups <cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"Mel Gorman" <mgorman-l3A5Bk7waGM@public.gmane.org>,
"David Rientjes"
<rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
"缪 勰" <miaox-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>,
"Andrew Morton"
<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Subject: Re: [RFC][PATCH] cgroup: fix race between fork and cgroup freezing
Date: Fri, 09 Mar 2012 14:26:05 +0800 [thread overview]
Message-ID: <4F59A27D.9080705@cn.fujitsu.com> (raw)
In-Reply-To: <20120308182622.GC25508-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
02:26, Tejun Heo wrote:
> Hello, Li, Frederic.
>
> On Thu, Mar 08, 2012 at 04:45:13PM +0800, Li Zefan wrote:
>> +static void freezer_post_fork(struct cgroup_subsys *ss,
>> + struct task_struct *task)
>> +{
>> + struct freezer *freezer;
>> +
>> + cgroup_lock();
>> +
>> + freezer = task_freezer(task);
>> + if (!freezer->css.cgroup->parent)
>> + goto out;
>> +
>> + spin_lock_irq(&freezer->lock);
>> + if (freezer->state != CGROUP_THAWED)
>> + freeze_task(task);
>> + spin_unlock_irq(&freezer->lock);
>> +out:
>> + cgroup_unlock();
>> +}
>
> Urgh... this is requiring policy implementations to synchronize with
> problem caused by cgroup core optimization and it's so very subtle.
> IMHO, this definitely should be contained in cgroup core and in a very
> confined form even inside cgroup core.
>
> Any other ideas?
>
The problem is, forks can happen at any time, so there's no way to prevent
forks from happening while iterating tasks in a cgroup, so controllers
have to deal with it. In fact freezer is somewhat aware of this issue,
that's why it provides the ->fork callback, but there's race.
This patch is not too bad (needs a bit modification). cgroup core will detect
(via seqcount) if something's happened to a cgroup and the tasks in it, and
then cgroup will notify controllers to check if newly-forked tasks should
be adjusted accordingly, so they will have consistent status with other tasks
in the same cgroup.
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizf@cn.fujitsu.com>
To: Tejun Heo <tj@kernel.org>
Cc: "Frederic Weisbecker" <fweisbec@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Cgroups <cgroups@vger.kernel.org>, "Mel Gorman" <mgorman@suse.de>,
"David Rientjes" <rientjes@google.com>,
"缪 勰" <miaox@cn.fujitsu.com>,
"Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: [RFC][PATCH] cgroup: fix race between fork and cgroup freezing
Date: Fri, 09 Mar 2012 14:26:05 +0800 [thread overview]
Message-ID: <4F59A27D.9080705@cn.fujitsu.com> (raw)
In-Reply-To: <20120308182622.GC25508@google.com>
02:26, Tejun Heo wrote:
> Hello, Li, Frederic.
>
> On Thu, Mar 08, 2012 at 04:45:13PM +0800, Li Zefan wrote:
>> +static void freezer_post_fork(struct cgroup_subsys *ss,
>> + struct task_struct *task)
>> +{
>> + struct freezer *freezer;
>> +
>> + cgroup_lock();
>> +
>> + freezer = task_freezer(task);
>> + if (!freezer->css.cgroup->parent)
>> + goto out;
>> +
>> + spin_lock_irq(&freezer->lock);
>> + if (freezer->state != CGROUP_THAWED)
>> + freeze_task(task);
>> + spin_unlock_irq(&freezer->lock);
>> +out:
>> + cgroup_unlock();
>> +}
>
> Urgh... this is requiring policy implementations to synchronize with
> problem caused by cgroup core optimization and it's so very subtle.
> IMHO, this definitely should be contained in cgroup core and in a very
> confined form even inside cgroup core.
>
> Any other ideas?
>
The problem is, forks can happen at any time, so there's no way to prevent
forks from happening while iterating tasks in a cgroup, so controllers
have to deal with it. In fact freezer is somewhat aware of this issue,
that's why it provides the ->fork callback, but there's race.
This patch is not too bad (needs a bit modification). cgroup core will detect
(via seqcount) if something's happened to a cgroup and the tasks in it, and
then cgroup will notify controllers to check if newly-forked tasks should
be adjusted accordingly, so they will have consistent status with other tasks
in the same cgroup.
next prev parent reply other threads:[~2012-03-09 6:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-08 8:45 [RFC][PATCH] cgroup: fix race between fork and cgroup freezing Li Zefan
2012-03-08 8:45 ` Li Zefan
[not found] ` <4F587199.6050404-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-03-08 18:26 ` Tejun Heo
2012-03-08 18:26 ` Tejun Heo
[not found] ` <20120308182622.GC25508-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-03-09 6:26 ` Li Zefan [this message]
2012-03-09 6:26 ` Li Zefan
[not found] ` <4F59A27D.9080705-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-03-09 16:53 ` Tejun Heo
2012-03-09 16:53 ` Tejun Heo
2012-03-12 9:02 ` Li Zefan
[not found] ` <4F5DBB8C.6090904-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-03-12 16:10 ` Tejun Heo
2012-03-12 16:10 ` Tejun Heo
[not found] ` <20120312161040.GA23255-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-03-19 13:44 ` Frederic Weisbecker
2012-03-19 13:44 ` Frederic Weisbecker
2012-03-19 15:05 ` Frederic Weisbecker
2012-03-19 15:05 ` Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F59A27D.9080705@cn.fujitsu.com \
--to=lizf-bthxqxjhjhxqfuhtdcdx3a@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mgorman-l3A5Bk7waGM@public.gmane.org \
--cc=miaox-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org \
--cc=rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.