Skip to content

Commit 7ceff01

Browse files
Daisuke NishimuraIngo Molnar
authored andcommitted
sched: Fix cgroup movement of newly created process
There is a small race between do_fork() and sched_move_task(), which is trying to move the child. do_fork() sched_move_task() --------------------------------+--------------------------------- copy_process() sched_fork() task_fork_fair() -> vruntime of the child is initialized based on that of the parent. -> we can see the child in "tasks" file now. task_rq_lock() task_move_group_fair() -> child.se.vruntime -= (old)cfs_rq->min_vruntime += (new)cfs_rq->min_vruntime task_rq_unlock() wake_up_new_task() ... enqueue_entity() child.se.vruntime += cfs_rq->min_vruntime As a result, vruntime of the child becomes far bigger than min_vruntime, if (new)cfs_rq->min_vruntime >> (old)cfs_rq->min_vruntime. This patch fixes this problem by just ignoring such process in task_move_group_fair(), because the vruntime has already been normalized in task_fork_fair(). Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/r/20111215143607.2ee12c5d.nishimura@mxp.nes.nec.co.jp Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 4fc420c commit 7ceff01

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎kernel/sched/fair.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5338,6 +5338,19 @@ static void task_move_group_fair(struct task_struct *p, int on_rq)
53385338
* to another cgroup's rq. This does somewhat interfere with the
53395339
* fair sleeper stuff for the first placement, but who cares.
53405340
*/
5341+
/*
5342+
* When !on_rq, vruntime of the task has usually NOT been normalized.
5343+
* But there are some cases where it has already been normalized:
5344+
*
5345+
* - Moving a forked child which is waiting for being woken up by
5346+
* wake_up_new_task().
5347+
*
5348+
* To prevent boost or penalty in the new cfs_rq caused by delta
5349+
* min_vruntime between the two cfs_rqs, we skip vruntime adjustment.
5350+
*/
5351+
if (!on_rq && !p->se.sum_exec_runtime)
5352+
on_rq = 1;
5353+
53415354
if (!on_rq)
53425355
p->se.vruntime -= cfs_rq_of(&p->se)->min_vruntime;
53435356
set_task_rq(p, task_cpu(p));

0 commit comments

Comments
 (0)