Commit d245698
committed
cgroup: Defer task cgroup unlink until after the task is done switching out
When a task exits, css_set_move_task(tsk, cset, NULL, false) unlinks the task
from its cgroup. From the cgroup's perspective, the task is now gone. If this
makes the cgroup empty, it can be removed, triggering ->css_offline() callbacks
that notify controllers the cgroup is going offline resource-wise.
However, the exiting task can still run, perform memory operations, and schedule
until the final context switch in finish_task_switch(). This creates a confusing
situation where controllers are told a cgroup is offline while resource
activities are still happening in it. While this hasn't broken existing
controllers, it has caused direct confusion for sched_ext schedulers.
Split cgroup_task_exit() into two functions. cgroup_task_exit() now only calls
the subsystem exit callbacks and continues to be called from do_exit(). The
css_set cleanup is moved to the new cgroup_task_dead() which is called from
finish_task_switch() after the final context switch, so that the cgroup only
appears empty after the task is truly done running.
This also reorders operations so that subsys->exit() is now called before
unlinking from the cgroup, which shouldn't break anything.
Cc: Dan Schatzberg <dschatzberg@meta.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Tejun Heo <tj@kernel.org>1 parent 260fbcb commit d245698
3 files changed
Lines changed: 18 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| |||
681 | 682 | | |
682 | 683 | | |
683 | 684 | | |
| 685 | + | |
684 | 686 | | |
685 | 687 | | |
686 | 688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
944 | 944 | | |
945 | 945 | | |
946 | 946 | | |
947 | | - | |
| 947 | + | |
948 | 948 | | |
949 | 949 | | |
950 | 950 | | |
| |||
6982 | 6982 | | |
6983 | 6983 | | |
6984 | 6984 | | |
6985 | | - | |
6986 | 6985 | | |
6987 | 6986 | | |
6988 | | - | |
| 6987 | + | |
| 6988 | + | |
| 6989 | + | |
| 6990 | + | |
| 6991 | + | |
| 6992 | + | |
| 6993 | + | |
| 6994 | + | |
| 6995 | + | |
| 6996 | + | |
| 6997 | + | |
| 6998 | + | |
6989 | 6999 | | |
6990 | 7000 | | |
6991 | 7001 | | |
| |||
7003 | 7013 | | |
7004 | 7014 | | |
7005 | 7015 | | |
7006 | | - | |
7007 | | - | |
7008 | | - | |
7009 | | - | |
7010 | | - | |
7011 | | - | |
| 7016 | + | |
7012 | 7017 | | |
7013 | 7018 | | |
7014 | 7019 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5222 | 5222 | | |
5223 | 5223 | | |
5224 | 5224 | | |
| 5225 | + | |
| 5226 | + | |
5225 | 5227 | | |
5226 | 5228 | | |
5227 | 5229 | | |
| |||
0 commit comments