Re: [PATCH v3] mm: memcontrol: don't miss processes whose leader has exited in OOM scans

From: Tejun Heo

Date: Mon Nov 23 2026 - 06:13:42 EST


Hello, Michal.

On Mon, Nov 23, 2026 at 11:11:27AM +0100, Michal Hocko wrote:
> Tejun, is there any strong reason to keep the exiting thread group
> leader in the original cgroup? This makes CSS_TASK_ITER_PROCS iteration
> really tricky and error prone as above examples show.

No, and I agree that the leader should follow the rest of the process on
cgroup.procs migrations. It's this way because controllers primarily care
about resources and exiting and zombie tasks don't matter much in that
regard, so migration skips them and controllers don't have to deal with
them. I don't want to change that. It doesn't make much sense to teach
all controllers about them.

That rules out the full migration path for the leader, and moving it
without one looks fragile. If cgroup core switches its css_set without
involving the controllers, ->release() sees a different css from the one
the task exited in, which breaks e.g. pids uncharging, and that still
doesn't work for a leader which is exiting but not dead yet as it's still
running.

Maybe the leader can pretend to be in the new cgroup instead. On
cgroup.procs migrations, record the destination css_set in an exiting or
dead leader without touching the css_set it's actually on. When a
CSS_TASK_ITER_PROCS iteration finds the first live thread of a process
whose leader is exiting or dead, it looks at the leader and visits it
there if the recorded css_set agrees.

That leaves the leader's actual css_set and everything that the
controllers see as they are now. Only the iteration changes, and exiting
and dead leaders are handled the same way.

Thanks.

--
tejun