cgroup: Return error when attempting to migrate a zombie process
Michal Koutný
maintainerRFC PATCH 1/1 cgroup: Return error when attempting to migrate a zombie process
Zombies aren't migrated. However, return value of a migration write may suggest a zombie process was migrated and causing confusion about lack of cgroup.events:populated between origin and target cgroups (e.g. target cgroup rmdir).
Notify the users about no effect of their action by a return value. (update_dfl_csses migration of zombies still silently passes since it is not meant to be user-visible migration anyway.)
--- kernel/cgroup/cgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Reasons for RFC:
1) Some users may notice the change,
2) EINVAL vs ESCHR,
3) add a selftest?
kernel/cgroup/cgroup.c +2 -1
@@ -2968,7 +2968,8 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,* become trapped in a cpuset, or RT kthread may be born in a * cgroup with no rt_runtime allocated. Just say no. */ -if (tsk->no_cgroup_migration || (tsk->flags &PF_NO_SETAFFINITY )) { +if (tsk->no_cgroup_migration || (tsk->flags &PF_NO_SETAFFINITY ) || + !atomic_read (&tsk->signal->live)) { tsk =ERR_PTR (-EINVAL ); goto out_unlock_threadgroup; }
Signature · 1 line
2.40.1
Tejun Heo
maintainerHello,
Quoted 25 lines · Michal Koutný
Zombies aren't migrated. However, return value of a migration write may suggest a zombie process was migrated and causing confusion about lack of cgroup.events:populated between origin and target cgroups (e.g. target cgroup rmdir).
Notify the users about no effect of their action by a return value. (
update_dfl_cssesmigration of zombies still silently passes since it is not meant to be user-visible migration anyway.)Suggested-by Benjamin Berg <[email protected]>Signed-off-by Michal Koutný <mkoutny-IBi9RG/[email protected]>--- kernel/cgroup/cgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Reasons for RFC:
1) Some users may notice the change,
2) EINVAL vs ESCHR,
3) add a selftest?kernel/cgroup/cgroup.c +0
-0
kernel/cgroup/cgroup.c struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup, · line 2972
Quoted 6 lines
kernel/cgroup/cgroup.c +2
-1@@ -2968,7 +2968,8 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,* become trapped in a cpuset, or RT kthread may be born in a * cgroup with no rt_runtime allocated. Just say no. */ -if (tsk->no_cgroup_migration || (tsk->flags &PF_NO_SETAFFINITY )) { +if (tsk->no_cgroup_migration || (tsk->flags &PF_NO_SETAFFINITY ) || + !atomic_read (&tsk->signal->live)) {
This seems racy to me. The liveness state can change between here and the PF_EXITING check in cgroup_migrate_add_task(), right? Wouldn't it be better to just track how many tasks are tracked and return -ESRCH if none was migrated?
Thanks.
Signature · 1 line
tejun
Michal Koutný
maintainerQuoted 2 lines · Tejun Heo
This seems racy to me. The liveness state can change between here and the
PF_EXITINGcheck incgroup_migrate_add_task(), right?
You're right, threadgroup lock won't prevent that (as I got wrongly in the patch):
cgroup_procs_write_start
do_exit
exit_signals
cgroup_threadgroup_change_begin
tsk->flags |= PF_EXITING
cgroup_threadgroup_change_end
percpu_down_write(&cgroup_threadgroup_rwsem)
...
atomic_read(&live)
...
atomic_dec_and_test(live)
...
cgroup_migrate_add_task
...
percpu_up_write(&cgroup_threadgroup_rwsem)Quoted 2 lines
Wouldn't it be better to just track how many tasks are tracked and return
-ESRCHif none was migrated?
Thanks, such an integral sounds better, will see.
Michal