[PATCH v2] PM / Freezer: Skip dead/zombie processes

Zihuan Zhang posted 1 patch 6 months, 3 weeks ago
There is a newer version of this series
kernel/power/process.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] PM / Freezer: Skip dead/zombie processes
Posted by Zihuan Zhang 6 months, 3 weeks ago
ZOMBIE (exit_state == EXIT_ZOMBIE) and DEAD (exit_state == EXIT_DEAD)
processes have already finished execution and will not be scheduled again.

In the context of system suspend (e.g., S3), attempting to freeze such
processes is unnecessary. Moreover, freezing them can obscure suspend
diagnostics and delay resume if they appear "stuck" in logs.

This patch introduces an early check for `p->exit_state != 0` in
`try_to_freeze_tasks()` and skips freezing for such tasks. This is a safe
optimization because:

 - They hold no running resources
 - Their `task_struct` is only waiting to be collected or freed

Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>

Changes in v2:
- Simplified code, added judgment of dead processes
- Rewrite changelogs
---
 kernel/power/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/power/process.c b/kernel/power/process.c
index 66ac067d9ae6..82528a79d46a 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -51,7 +51,7 @@ static int try_to_freeze_tasks(bool user_only)
 		todo = 0;
 		read_lock(&tasklist_lock);
 		for_each_process_thread(g, p) {
-			if (p == current || !freeze_task(p))
+			if (p == current || p->exit_state || !freeze_task(p))
 				continue;
 
 			todo++;
-- 
2.25.1
Re: [PATCH v2] PM / Freezer: Skip dead/zombie processes
Posted by Rafael J. Wysocki 6 months, 3 weeks ago
On Fri, May 23, 2025 at 5:44 AM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> ZOMBIE (exit_state == EXIT_ZOMBIE) and DEAD (exit_state == EXIT_DEAD)
> processes have already finished execution and will not be scheduled again.
>
> In the context of system suspend (e.g., S3), attempting to freeze such
> processes is unnecessary. Moreover, freezing them can obscure suspend
> diagnostics and delay resume if they appear "stuck" in logs.
>
> This patch introduces an early check for `p->exit_state != 0` in
> `try_to_freeze_tasks()` and skips freezing for such tasks. This is a safe
> optimization because:
>
>  - They hold no running resources
>  - Their `task_struct` is only waiting to be collected or freed
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
>
> Changes in v2:
> - Simplified code, added judgment of dead processes
> - Rewrite changelogs
> ---
>  kernel/power/process.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/power/process.c b/kernel/power/process.c
> index 66ac067d9ae6..82528a79d46a 100644
> --- a/kernel/power/process.c
> +++ b/kernel/power/process.c
> @@ -51,7 +51,7 @@ static int try_to_freeze_tasks(bool user_only)
>                 todo = 0;
>                 read_lock(&tasklist_lock);
>                 for_each_process_thread(g, p) {
> -                       if (p == current || !freeze_task(p))
> +                       if (p == current || p->exit_state || !freeze_task(p))
>                                 continue;
>
>                         todo++;
> --

This is a bit too late for 6.16, please resubmit when 6.16-rc1 is out.

Thanks!