Re: Q: css_task_iter_advance() && dying_tasks

From: Tejun Heo
Date: Mon Jun 10 2024 - 16:01:02 EST


Hello, Oleg.

On Mon, Jun 10, 2024 at 12:50:28PM +0200, 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 ?

Yeah, I think so. The current code hasn't broken for quite a while but it
also hasn't received much attention after the iterator updates which were
very much in the spirit of just getting it to work. I don't think you're
missing anything.

> 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()

That does sound a lot better than the current code. Care to send the patch?

Thanks.

--
tejun