Re: [PATCH v3 4/7] cgroup: cgroup v2 freezer
From: Roman Gushchin
Date: Tue Nov 20 2018 - 11:34:16 EST
On Tue, Nov 20, 2018 at 08:25:29AM -0800, Tejun Heo wrote:
> On Fri, Nov 16, 2018 at 04:38:27PM -0800, Roman Gushchin wrote:
> > +void cgroup_freezer_migrate_task(struct task_struct *task,
> > + struct cgroup *src, struct cgroup *dst)
> > +{
> > + lockdep_assert_held(&css_set_lock);
> > +
> > + /*
> > + * Kernel threads are not supposed to be frozen at all.
> > + */
> > + if (task->flags & PF_KTHREAD)
> > + return;
> > +
> > + /*
> > + * Adjust counters of freezing and frozen tasks.
> > + */
> > + if (test_bit(CGRP_FREEZE, &src->flags)) {
> > + src->freezer.nr_tasks_to_freeze--;
> > + WARN_ON_ONCE(src->freezer.nr_tasks_to_freeze < 0);
> > + }
> > +
> > + /*
> > + * If the task is frozen, let's bump nr_tasks_to_freeze even
> > + * if the target cgroup isn't frozen: the counter will be decreased
> > + * in cgroup_leave_frozen().
> > + */
> > + if (test_bit(CGRP_FREEZE, &dst->flags) || task->frozen)
> > + dst->freezer.nr_tasks_to_freeze++;
> > +
> > + if (task->frozen) {
> > + src->freezer.nr_frozen_tasks--;
> > + dst->freezer.nr_frozen_tasks++;
> > + WARN_ON_ONCE(src->freezer.nr_frozen_tasks < 0);
> > + WARN_ON_ONCE(dst->freezer.nr_frozen_tasks >
> > + dst->freezer.nr_tasks_to_freeze);
> > + }
>
> If a non-frozen task is being moved into a frozen cgroup, shouldn't
> that also trigger frozen state update?
It does! Just below these lines:
/*
* If the task isn't in the desired state, force it to it.
*/
if (task->frozen != test_bit(CGRP_FREEZE, &dst->flags))
cgroup_freeze_task(task, test_bit(CGRP_FREEZE, &dst->flags));
It's also covered by the 5th kselftest.
Thanks!