Skip to content

Commit 0cd9d33

Browse files
committed
cgroup: init_tasks shouldn't be linked to the root cgroup
5153faa ("cgroup: remove cgroup_enable_task_cg_lists() optimization") removed lazy initialization of css_sets so that new tasks are always lniked to its css_set. In the process, it incorrectly ended up adding init_tasks to root css_set. They show up as PID 0's in root's cgroup.procs triggering warnings in systemd and generally confusing people. Fix it by skip css_set linking for init_tasks. Signed-off-by: Tejun Heo <[email protected]> Reported-by: https://github.com/joanbm Link: systemd/systemd#14682 Fixes: 5153faa ("cgroup: remove cgroup_enable_task_cg_lists() optimization") Cc: [email protected] # v5.5+
1 parent 39bed42 commit 0cd9d33

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kernel/cgroup/cgroup.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5932,11 +5932,14 @@ void cgroup_post_fork(struct task_struct *child)
59325932

59335933
spin_lock_irq(&css_set_lock);
59345934

5935-
WARN_ON_ONCE(!list_empty(&child->cg_list));
5936-
cset = task_css_set(current); /* current is @child's parent */
5937-
get_css_set(cset);
5938-
cset->nr_tasks++;
5939-
css_set_move_task(child, NULL, cset, false);
5935+
/* init tasks are special, only link regular threads */
5936+
if (likely(child->pid)) {
5937+
WARN_ON_ONCE(!list_empty(&child->cg_list));
5938+
cset = task_css_set(current); /* current is @child's parent */
5939+
get_css_set(cset);
5940+
cset->nr_tasks++;
5941+
css_set_move_task(child, NULL, cset, false);
5942+
}
59405943

59415944
/*
59425945
* If the cgroup has to be frozen, the new task has too. Let's set

0 commit comments

Comments
 (0)