public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Andrey Vagin <avagin@openvz.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Li Zefan <lizf@cn.fujitsu.com>,
	Matt Helsley <matthltc@us.ibm.com>,
	Pavel Emelyanov <xemul@parallels.com>, Tejun Heo <tj@kernel.org>
Subject: Re: [RFC] cgroups: freezer -- Allow to attach a task to a frozen cgroup
Date: Mon, 28 Nov 2011 17:38:28 +0400	[thread overview]
Message-ID: <20111128133828.GL1775@moon> (raw)
In-Reply-To: <CANaxB-wrRd94OJifpYJ=kibx_48oJ=GE51f9GWjZ3np2nCQYsA@mail.gmail.com>

On Mon, Nov 28, 2011 at 05:10:00PM +0400, Andrey Vagin wrote:
> >        void (*cancel_attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
> > -                             struct task_struct *tsk);
> > +                             struct cgroup *old_cgrp, struct task_struct *tsk);
> 
> I'm not shure, that we need old_cgrp, because when cancel_attach is
> executed, a task is in old cgroup and old_cgrp = task_cgroup(tsk);
> 
> ...
> 

Yup, thanks for the point. Indeed old_cgrp is redundant and task_cgroup
helper will provide all additional information we need.

> > +
> > +static int freezer_can_attach_task(struct cgroup *cgroup, struct task_struct *task)
> > +{
> > +       struct freezer *old_freezer;
> > +       struct freezer *freezer;
> > +
> > +       int goal_state, orig_state;
> > +       int retval = 0;
> > +
> > +       old_freezer = task_freezer(task);
> > +       freezer = cgroup_freezer(cgroup);
> > +
> > +       spin_lock_irq(&freezer->lock);
> > +
> > +       if (!spin_trylock_irq(&old_freezer->lock)) {
> > +               retval = -EBUSY;
> 
> I think EBUSY is not a good idea in this place.  We can do something
> like double_rq_lock.
> 

Could you please elaborate? freezers are guarded with spinlocks so I think
we should stick with them instead of poking rq (or whatever) directly.

> 
> > +
> > +static void freezer_cancel_attach(struct cgroup_subsys *ss,
> > +                                 struct cgroup *cgroup,
> > +                                 struct cgroup *old_cgroup,
> > +                                 struct task_struct *task)
> > +{
> > +       struct freezer *freezer = cgroup_freezer(old_cgroup);
> > +       int retval = 0;
> > +
> > +       spin_lock_irq(&freezer->lock);
> > +       retval = freezer_task_transition(task, freezer->state);
> > +       if (retval)
> > +               pr_warning("freezer: Can't move task (pid %d) to %s state\n",
> > +                          task_pid_nr(task),
> > +                          freezer_state_strs[freezer->state]);
> 
> It's strange. A rollback can't fail. We have three situations:
> 
> frozen -> frozen
> thawed -> frozen
> frozen -> thawed
> 
> In first and second cases cancel_request can't fail.
> In the third we have a problem, which may be solved if we will call
> thaw_process(task) from attach_task(), we can do that, because
> thaw_process() can't fail. It solves a problem, because
> freezer_cancel_attach will be executed for the first and second cases
> only.
> 
> If my suggestion is correct, we can replace pr_warning on BUG_ON
> 

Yes, the case which can fail is

   frozen->(can_attach_task)->thawed
     (cgroup_task_migrate failure)
   thawed->(cancel_attach)->frozen

and we should never fail here since otherwise we would not have
a "frozen" state before. But I think placing BUG_ON is too severe
here, maybe WARN_ON_ONCE(1) would fit better?

  reply	other threads:[~2011-11-28 13:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28 12:08 [RFC] cgroups: freezer -- Allow to attach a task to a frozen cgroup Cyrill Gorcunov
2011-11-28 13:10 ` Andrey Vagin
2011-11-28 13:38   ` Cyrill Gorcunov [this message]
2011-11-28 14:03     ` Andrew Vagin
2011-11-28 15:00       ` Cyrill Gorcunov
2011-11-28 15:43         ` Andrew Wagin
2011-11-28 16:08 ` Tejun Heo
2011-11-28 16:31   ` Cyrill Gorcunov
2011-11-29 22:58   ` Matt Helsley
2011-11-29 23:19     ` Tejun Heo
2011-11-30  6:48     ` Cyrill Gorcunov

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=20111128133828.GL1775@moon \
    --to=gorcunov@gmail.com \
    --cc=avagin@openvz.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=matthltc@us.ibm.com \
    --cc=tj@kernel.org \
    --cc=xemul@parallels.com \
    /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