Re: [PATCH v3 1/1] PM / Freezer: Skip zombie/dead processes to
From: Peter Zijlstra
Date: Fri Jul 04 2025 - 05:26:44 EST
On Fri, Jul 04, 2025 at 04:48:20PM +0800, Zihuan Zhang wrote:
> Hi Peter,
>
> Thanks for the feedback.
>
> ??? 2025/7/4 16:19, Peter Zijlstra ??????:
> > ????????? ??? ??? ?????? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??????
> > Depending on where they wait (I can't seem to find in a hurry) it might
> > make sense to make that wait FREEZABLE anyway.
> >
> > For example, AFAICT it wouldn't hurt, and might even help some, to make
> > kernel/exit.c:do_wait() TASK_FREEZABLE.
> >
> > So where do ZOMBIEs sleep? Don't they simply pass through do_task_dead()
> > and never get scheduled again? Notably, do_task_dead() already marks the
> > tasks as PF_NOFREEZE.
> >
> > Anyway, yes, the condition it adds is relatively simple, but I really
> > don't see why we should complicate things *at*all*.
>
> You???re absolutely right ??? zombie processes won???t be frozen in
> practice, since PF_NOFREEZE is already set in do_task_dead(). However, if we
> don???t explicitly skip them early in try_to_freeze_task(), they still go
> through the freezer logic path, including calls like freeze_task() ???
> freezing() before eventually returning without freezing.
>
> This not only introduces unnecessary code path traversal, but also involves
> locking (e.g., spin_lock_irqsave/restore()), which could be avoided
> altogether if we bail out earlier.
>
> Additionally, skipping zombies directly helps reduce the list traversal
> overhead in freeze_processes(), especially on systems with a large number of
> tasks, where zombies can account for a non-trivial fraction.
>
> So while the practical effect might be small, the gain is low-risk and helps
> streamline the freezer logic a bit more.
You're missing the obvious. How about we 'fix' the PF_NOFREEZE handling
and help all cases that set that and not only zombies?