Re: [PATCH v4] PM / Freezer: Skip zombie/dead processes to reduce freeze latency
From: Zihuan Zhang
Date: Thu Jul 17 2025 - 04:46:10 EST
Hi Oleg,
在 2025/7/17 09:31, Oleg Nesterov 写道:
Hi Zihuan,
On 07/17, Zihuan Zhang wrote:
+ */
+ if (p == current || p->exit_state || !freeze_task(p))
continue;
I leave this to you and Rafael, but this change doesn't look safe to me.
What if the exiting task does some IO after exit_notify() ?
Tasks that have passed exit_notify() and entered EXIT_ZOMBIE are no longer
schedulable,
How so? please look at do_exit(). The exiting task is still running
until it does its last __schedule() in do_task_dead().
To verify the potential presence of EXIT_DEAD tasks during the freezing
stage, I added some logging in try_to_freeze_tasks() to print out any
task with exit_state == EXIT_DEAD. Then I created a fork storm scenario
to ensure a large number of tasks are exiting during the freeze window.
In practice, even after running hundreds of iterations under heavy load,
I wasn’t able to capture any such task being printed. Since the exit
phase is very fast, it seems unlikely that an EXIT_DEAD task stays in
the process list long enough to be observed during the freeze loop.
So I believe it's safe to skip tasks with exit_state in this context.
diff --git a/kernel/power/process.c b/kernel/power/process.c
index c1d6c5150033..054fad43ed31 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -59,6 +59,8 @@ static int try_to_freeze_tasks(bool user_only)
* a more generic exclusion mechanism for other
non-freezable tasks.
* However, for now, exit_state is sufficient
to skip user processes.
*/
+ if (p->exit_state == EXIT_DEAD)
+ pr_info("current process is going to
dead name:%s pid:%d \n", p->comm, p->pid);
if (p == current || p->exit_state ||
!freeze_task(p))
continue;
so they cannot do I/O anymore. Skipping them during freezing
should be safe
Oleg.