linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Gushchin <guroan@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Tejun Heo <tj@kernel.org>,
	kernel-team@fb.com, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, Roman Gushchin <guro@fb.com>
Subject: Re: [PATCH v6 4/7] cgroup: cgroup v2 freezer
Date: Mon, 28 Jan 2019 11:59:04 -0800	[thread overview]
Message-ID: <CALo0P13XnGiFykMXY3ZKu158ZqnBwHru0gyhQUrJSHEprnmiHQ@mail.gmail.com> (raw)
In-Reply-To: <20190125122713.GA18218@redhat.com>

Hi Oleg!

Thank you for looking into the patchset!

Yes, I think you're right: cgroup_exit() should check CGRP_FREEZE bit,
not CGRP_FROZEN. Like cgroup_post_fork() does (a one-liner change below).

About spurious transitions (like frozen->non frozen->frozen on a task
being SIGKILLed):
in early versions of the patchset I've tried to avoid them, but then
following the Tejun's advice
switched over to expose them to a user. The logic behind is simple: if
the state of the cgroup has been changed (a task is gone, for
example), let's notify a user.

nr_tasks_to_freeze is simple a number of non-kthead tasks in the
cgroup, which we do
keep actual only for freezing cgroups (to avoid an unnecessary overhead).

Thanks!

--

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 3e6a7c19bfaf..08c84d2145eb 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5832,7 +5832,7 @@ void cgroup_exit(struct task_struct *tsk)
                css_set_move_task(tsk, cset, NULL, false);
                cset->nr_tasks--;

-               if (unlikely(test_bit(CGRP_FROZEN, &cset->dfl_cgrp->flags))) {
+               if (unlikely(cgroup_task_freeze(tsk))) {
                        /*
                         * Task frozen bit should be cleared at this moment,
                         * and nr_frozen_task should be decreased.

пт, 25 янв. 2019 г. в 04:27, Oleg Nesterov <oleg@redhat.com>:
>
> Sorry, this version raced with my vacation, I missed it.
>
> I'll try to read this code carefully but after a quick glance I have some
> concerns,
>
> On 12/21, Roman Gushchin wrote:
> >
> > +static void cgroup_update_frozen(struct cgroup *cgrp)
> > +{
> > +     bool frozen;
> > +
> > +     lockdep_assert_held(&css_set_lock);
> > +
> > +     /*
> > +      * If the cgroup has to be frozen (CGRP_FREEZE bit set),
> > +      * and all tasks are frozen or stopped, let's consider
> > +      * the cgroup frozen. Otherwise it's not frozen.
> > +      */
> > +     frozen = test_bit(CGRP_FREEZE, &cgrp->flags) &&
> > +             cgrp->freezer.nr_frozen_tasks +
> > +             cgrp->freezer.nr_stopped_tasks ==
> > +             cgrp->freezer.nr_tasks_to_freeze;
>
> OK. Suppose that cgroup is frozen, CGRP_FROZEN is set, stopped == 0,
> to_freeze = frozen.
>
> One of the task is killed, it calls leave_frozen(). If I read this code path
> correctly, only ->nr_frozen_tasks will be decremented, so "frozen" will be
> "false" when cgroup_update_frozen() is called.
>
> Doesn't this mean that this cgroup will no longer be CGRP_FROZEN even after
> the killed task goes away completely?
>
>
> Or. Suppose that another process picks a task from the CGRP_FROZEN cgroup and
> does PTRACE_ATTACH + PTRACE_INTERRUPT. IIUC, the tracee will only increment
> ->nr_stopped_tasks, it won't touch other counters. Again, cgroup won't be FROZEN
> until PTRACE_CONT'ed tracee does cgroup_leave_stopped() ? This looks strange at
> least.
>
>
>
> SIGSTOP. IIUC, a frozen task sleeping in do_freezer_trap() won't stop. However if
> another thread has already called do_signal_stop(), the woken frozen task will
> react to JOBCTL_STOP_PENDING and stop. And do_signal_stop()->cgroup_enter_stopped()
> will "destroy" CGRP_FROZEN too, or I am totally confused.
>
> OTOH, if you freeze a TASK_STOPPED task's cgroup, this task can react to SIGCONT,
> notify its parent, then freeze again. This is fine, but iiuc this cgroup won't be
> FROZEN in between, cgroup_file_notify() will be called twice...
>
> Oleg.
>

  parent reply	other threads:[~2019-01-28 19:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-22  0:03 [PATCH v6 0/7] freezer for cgroup v2 Roman Gushchin
2018-12-22  0:03 ` [PATCH v6 1/7] cgroup: rename freezer.c into legacy_freezer.c Roman Gushchin
2018-12-22  0:03 ` [PATCH v6 2/7] cgroup: implement __cgroup_task_count() helper Roman Gushchin
2018-12-22  0:03 ` [PATCH v6 3/7] cgroup: protect cgroup->nr_(dying_)descendants by css_set_lock Roman Gushchin
2018-12-22  0:03 ` [PATCH v6 4/7] cgroup: cgroup v2 freezer Roman Gushchin
2019-01-25 12:27   ` Oleg Nesterov
2019-01-25 13:46     ` Oleg Nesterov
2019-01-28 19:59     ` Roman Gushchin [this message]
2019-01-30 16:52       ` Oleg Nesterov
2019-02-11 21:30         ` Roman Gushchin
2019-02-14 16:26           ` Oleg Nesterov
2019-02-14 16:41             ` Roman Gushchin
2019-01-25 13:43   ` Oleg Nesterov
2018-12-22  0:03 ` [PATCH v6 5/7] kselftests: cgroup: don't fail on cg_kill_all() error in cg_destroy() Roman Gushchin
2018-12-22  0:03 ` [PATCH v6 6/7] kselftests: cgroup: add freezer controller self-tests Roman Gushchin
2018-12-22  0:03 ` [PATCH v6 7/7] cgroup: document cgroup v2 freezer interface Roman Gushchin
2019-01-24 15:26 ` [PATCH v6 0/7] 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=CALo0P13XnGiFykMXY3ZKu158ZqnBwHru0gyhQUrJSHEprnmiHQ@mail.gmail.com \
    --to=guroan@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=guro@fb.com \
    --cc=kernel-team@fb.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).