From: sashiko-bot@kernel.org
To: "Zhan Xusheng" <zhanxusheng1024@gmail.com>, tj@kernel.org
Cc: hannes@cmpxchg.org, mkoutny@suse.com, mhocko@suse.com,
roman.gushchin@linux.dev, shakeel.butt@linux.dev,
muchun.song@linux.dev, akpm@linux-foundation.org,
kolyshkin@gmail.com, chris@chrisdown.name, linux-mm@kvack.org,
zhanxusheng@xiaomi.com
Subject: Re: [PATCH 2/2] mm: memcontrol: find the OOM group of a process where its threads are
Date: Wed, 25 Nov 2026 03:36:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-232472@kernel.org> (raw)
In-Reply-To: <20261124033547.2373352-3-zhanxusheng1024@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mm: memcontrol: task_procs_css_set() returns stale css_set if
threads exit
- [Medium] cgroup: missing cg_leader_left update in
cgroup_update_dfl_csses()
- [Low] mm: memcontrol: use of task_cgroup() in
mem_cgroup_print_oom_context()
--
commit 00e8b03872e16150479767210c746337c6018f3f
Author: Zhan Xusheng <zhanxusheng@xiaomi.com>
mm: memcontrol: find the OOM group of a process where its threads are
This commit adds task_procs_css_set() and task_procs_css() to resolve the
css of a process returned by a CSS_TASK_ITER_PROCS walk via
procs_live_thread(), and uses it in mem_cgroup_get_oom_group() so that a
migrated process with an exited thread group leader is matched against the
memcg where its live threads reside.
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index ab442f94e29d2..0be7f96ce074d 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -5237,6 +5237,17 @@ static bool procs_stand_in(struct task_struct *task)
> return leader != task && procs_live_thread(leader) == task;
> }
>
> +/**
> + * task_procs_css_set - css_set of the process a PROCS walk returned
> + * @task: the task returned by the walk
> + *
> + * See task_procs_css().
> + */
> +struct css_set *task_procs_css_set(struct task_struct *task)
> +{
> + return task_css_set(procs_live_thread(task));
> +}
[Severity: Medium]
Can task_procs_css_set() return the exited leader's old css_set if the
remaining threads in the destination cgroup enter do_exit() before
mem_cgroup_get_oom_group() runs?
When the victim is an exited leader left behind by a cgroup.procs
migration, victim->mm is NULL, so task_will_free_mem(victim) in
oom_kill_process() returns false and does not short-circuit before
mem_cgroup_get_oom_group(). If the remaining threads in the destination
cgroup set PF_EXITING between select_bad_process() and
mem_cgroup_get_oom_group() (for example while dump_header() is printing),
procs_live_thread() skips every thread with PF_EXITING and falls back to
returning the leader on the old css_set:
kernel/cgroup/cgroup.c:procs_live_thread() {
...
for_each_thread(leader, t) {
if (!(t->flags & PF_EXITING)) {
if (task_css_set(t) == task_css_set(leader))
return leader;
return t;
}
}
return leader;
}
mem_cgroup_get_oom_group() will then miss memory.oom.group on the
destination cgroup, or kill unrelated processes in the old source cgroup
if the old cgroup is also under oom_domain and has memory.oom.group set.
[Severity: Medium]
Does task_procs_css_set() also return the exited leader's stale css_set
after cgroup_update_dfl_csses() moves live threads to a new css_set on a
cgroup.subtree_control write?
When a thread group leader exits while sibling threads remain alive,
do_cgroup_task_dead() moves the leader to src_cset->dying_tasks. If a
controller such as memory is then enabled on an ancestor,
cgroup_update_dfl_csses() migrates only tasks on src_cset->tasks to the
new dst_cset, leaving the exited leader on src_cset->dying_tasks without
setting leader->cg_leader_left = true (which is only set in
cgroup_migrate()). Because cg_leader_left is still false,
procs_live_thread() returns the leader on src_cset, so
task_procs_css() in mem_cgroup_get_oom_group() resolves to the ancestor's
memcg on src_cset instead of the child's new memcg on dst_cset, and
CSS_TASK_ITER_PROCS walks on the child's new CSS skip the process because
procs_stand_in() evaluates to false.
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 1271d390b617e..5704e4415a16f 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2003,7 +2003,7 @@ struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim,
>
> rcu_read_lock();
>
> - memcg = mem_cgroup_from_task(victim);
> + memcg = mem_cgroup_from_css(task_procs_css(victim, memory_cgrp_id));
> if (mem_cgroup_is_root(memcg))
> goto out;
[Severity: Low]
Should mem_cgroup_print_oom_context() also use task_procs_css() instead of
task_cgroup(p, memory_cgrp_id)?
oom_kill_process() passes the same victim task to dump_oom_victim() right
before calling mem_cgroup_get_oom_group(), so task_memcg= in the OOM log
will still print the old source cgroup where the exited leader was left
behind.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124033547.2373352-1-zhanxusheng1024@gmail.com?part=2
next prev parent reply other threads:[~2026-11-25 3:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 3:35 [PATCH 0/2] cgroup: list processes whose leader has exited where their threads are Zhan Xusheng
2026-11-24 3:35 ` [PATCH 1/2] cgroup: list a process whose leader has exited where its " Zhan Xusheng
2026-11-25 3:36 ` sashiko-bot
2026-11-24 3:35 ` [PATCH 2/2] mm: memcontrol: find the OOM group of a process " Zhan Xusheng
2026-11-25 3:36 ` sashiko-bot [this message]
2026-11-24 18:47 ` [PATCH 0/2] cgroup: list processes whose leader has exited where their " Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-232472@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chris@chrisdown.name \
--cc=hannes@cmpxchg.org \
--cc=kolyshkin@gmail.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox