Re: Q: css_task_iter_advance() && dying_tasks

From: Oleg Nesterov
Date: Mon Jun 10 2024 - 07:10:49 EST


Sorry for the spam, forgot to mention. Either way the usage of group_dead
or atomic_read(signal->live) in these paths doesn't look "perfect", but
this is another thing. The pseudo code below tries to mimic the current
logic but again, I'm afraid I misread this code completely.


On 06/10, Oleg Nesterov wrote:
>
> I never understood the code in kernel/cgroup/ even remotely, most probably
> I missed something, but let me ask a couple of stupid questions anyway.
>
> cgroup_exit() does
>
> css_set_move_task(tsk, cset, NULL, false);
> list_add_tail(&tsk->cg_list, &cset->dying_tasks);
>
> but unless I am totally confused css_task_iter_advance() always ignores
> the "dying" sub-threads, so perhaps it should do, say,
>
> css_set_move_task(tsk, cset, NULL, false);
> if (delay_group_leader(tsk))
> list_add_tail(&tsk->cg_list, &cset->dying_tasks);
>
> and then cgroup_release() can check list_empty(cg_list) before it takes
> css_set_lock.
>
> No ?
>
> Or, perhaps we can do even better? Can't cgroup_exit() do something like
>
> // group_dead should be passed from do_exit()
>
> css_set_move_task(tsk, cset, NULL, false);
>
> if (thread_group_leader(tsk) && !group_dead)
> list_add_tail(&tsk->cg_list, &cset->dying_tasks);
>
> else if (!thread_group_leader(tsk) && group_dead) {
> leader = tsk->group_leader;
> if (!list_empty(leader->cg_list) {
> css_set_skip_task_iters(task_css_set(leader), leader);
> list_del_init(&leader->cg_list);
> }
> }
>
> and then
>
> - kill the atomic_read(&task->signal->live)) check in
> css_task_iter_advance()
>
> - kill the code under css_set_lock in cgroup_release()
>
> Oleg.