From: Roman Gushchin <guro@fb.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Roman Gushchin <guroan@gmail.com>, Tejun Heo <tj@kernel.org>,
Kernel Team <Kernel-team@fb.com>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v10 4/9] cgroup: cgroup v2 freezer
Date: Wed, 24 Apr 2019 22:06:41 +0000 [thread overview]
Message-ID: <20190424220634.GA22896@tower.DHCP.thefacebook.com> (raw)
In-Reply-To: <20190424154619.GG16167@redhat.com>
On Wed, Apr 24, 2019 at 05:46:19PM +0200, Oleg Nesterov wrote:
> On 04/22, Roman Gushchin wrote:
> >
> > > > Hm, it might work too, but I'm not sure I like it more. IMO, the best option
> > > > is to have a single cgroup_leave_frozen(true) in signal.c, it's just simpler.
> > > > If a user changed the desired state of cgroup twice, there is no need to avoid
> > > > state transitions. Or maybe I don't see it yet.
> > >
> > > Then why do we need cgroup_leave_frozen(false) in wait_for_vfork_done() ? How
> > > does it differ from get_signal() ?
> >
> > We need it because sleeping in vfork is a special state which we want to
> > account as frozen. And if the parent process wakes up while the cgroup is frozen
> > (because of the child death, for example), we want to push it into the "proper"
> > frozen state without changing the state of the cgroup.
>
> Again, I do not see how vfork() differs from get_signal() in this respect.
>
> Let me provide another example. A TASK_STOPPED task reacts to SIGCONT and
> returns to get_signal(), current->frozen is true.
>
> If this races with CGRP_FREEZE, the task should not return to user-space,
> just like vfork(). I see no difference.
>
> They differ in that wait_for_vfork_done() should guarentee TIF_SIGPENDING
> in this case, but this is another story...
Right, I agree.
>
> >
> > > If nothing else. Suppose that wait_for_vfork_done() calls leave(false) and this
> > > races with freezer, CGRP_FREEZE is already set but JOBCTL_TRAP_FREEZE is not.
> > >
> > > This sets TIF_SIGPENDING to ensure the task won't return to user mode, thus it
> > > calls get_signal().
> > >
> > > get_signal() doesn't see JOBCTL_TRAP_FREEZE, it notices ->frozen == T and does
> > > cgroup_leave_frozen(true) which clears ->frozen.
> > >
> > > Then the task calls dequeue_signal(), clears TIF_SIGPENDING and returns to user
> > > mode?
> >
> > Got it, a good catch! So if the freezer races with vfork() completion, we might
> > have a spurious frozen->unfrozen->frozen transition of the cgroup state.
> >
> > Switching to cgroup_leave_frozen(false) seems to solve it, but I'm slightly
> > concerned that we're basically putting the task in a busy loop between
> > the setting CGRP_FREEZE and setting TRAP_FREEZE.
>
> Yes, yes. Didn't I say I dislike the new ->frozen check in recalc() ? ;)
>
> OK, how about the ABSOLUTELY UNTESTED patch below? For the start.
It looks good to me (and all freezer selftests pass).
Just to be sure, is it a solution to avoid the busy loop in the signal handling
loop, right? Because it doesn't allow to drop the ->frozen check from recalc().
The JOBCTL_TRAP_FREEZE check without siglock initially looked dangerous to me,
but after some thoughts I didn't find any case when it's wrong.
Do you prefer me to master a patch or to do it by yourself?
Thank you!
Roman
next prev parent reply other threads:[~2019-04-24 22:06 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 17:46 [PATCH v10 0/9] freezer for cgroup v2 Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 1/9] cgroup: rename freezer.c into legacy_freezer.c Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 2/9] cgroup: implement __cgroup_task_count() helper Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 3/9] cgroup: protect cgroup->nr_(dying_)descendants by css_set_lock Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 4/9] cgroup: cgroup v2 freezer Roman Gushchin
2019-04-19 15:19 ` Oleg Nesterov
2019-04-19 16:08 ` Oleg Nesterov
2019-04-19 16:36 ` Roman Gushchin
2019-04-19 16:11 ` Roman Gushchin
2019-04-19 16:26 ` Oleg Nesterov
2019-04-19 16:56 ` Roman Gushchin
2019-04-20 10:58 ` Oleg Nesterov
2019-04-22 22:11 ` Roman Gushchin
2019-04-24 15:46 ` Oleg Nesterov
2019-04-24 22:06 ` Roman Gushchin [this message]
2019-04-26 17:40 ` Oleg Nesterov
2019-04-24 16:02 ` Oleg Nesterov
2019-04-24 22:10 ` Roman Gushchin
2019-04-26 17:30 ` Oleg Nesterov
2019-04-05 17:47 ` [PATCH v10 5/9] kselftests: cgroup: don't fail on cg_kill_all() error in cg_destroy() Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 6/9] kselftests: cgroup: add freezer controller self-tests Roman Gushchin
2019-07-16 14:48 ` Naresh Kamboju
2019-07-17 0:49 ` Roman Gushchin
2019-07-17 8:56 ` Naresh Kamboju
2019-07-18 18:19 ` Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 7/9] cgroup: make TRACE_CGROUP_PATH irq-safe Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 8/9] cgroup: add tracing points for cgroup v2 freezer Roman Gushchin
2019-04-05 17:47 ` [PATCH v10 9/9] cgroup: document cgroup v2 freezer interface Roman Gushchin
2019-04-19 18:29 ` [PATCH v10 0/9] freezer for cgroup v2 Tejun Heo
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=20190424220634.GA22896@tower.DHCP.thefacebook.com \
--to=guro@fb.com \
--cc=Kernel-team@fb.com \
--cc=cgroups@vger.kernel.org \
--cc=guroan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=tj@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).