mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zihuan Zhang <zhangzihuan@kylinos.cn>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	pavel@kernel.org, len.brown@intel.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH v3 1/1] PM / Freezer: Skip zombie/dead processes to
Date: Mon, 7 Jul 2025 09:00:12 +0800	[thread overview]
Message-ID: <de7e327a-202c-4b28-b372-2d648c680dbe@kylinos.cn> (raw)
In-Reply-To: <20250704092144.GH2001818@noisy.programming.kicks-ass.net>


在 2025/7/4 17:21, Peter Zijlstra 写道:
> You're missing the obvious. How about we 'fix' the PF_NOFREEZE handling
> and help all cases that set that and not only zombies?                               

It sounds like a good idea, but there’s a potential risk in relying 
solely on PF_NOFREEZE: it’s a mutable flag that can be set or cleared 
dynamically during runtime, even within the freeze window.
If a task changes its PF_NOFREEZE state after passing the early check in 
try_to_freeze_task(), we might skip freezing it incorrectly, leading to 
inconsistent behavior or unexpected task escapes. This is particularly 
tricky for some kernel threads or exit paths where PF_NOFREEZE is 
manipulated as part of cleanup or teardown.
In contrast, checking exit_state for EXIT_ZOMBIE or EXIT_DEAD is fully 
stable and irreversible — once a task becomes a zombie, it's no longer 
schedulable and doesn’t require freezing. That makes the condition both 
safe and predictable, without risk of races or missed transitions.
Currently, the safest way to skip tasks based on PF_NOFREEZE would be:
*if (!(p->flags & PF_KTHREAD) && (p->flags & PF_NOFREEZE))*
to avoid skipping kernel threads that may dynamically toggle this flag. 
But this increases code complexity compared to simply checking
*if (p->exit_state)*

which is more straightforward.
Importantly, exit_state is set earlier and more reliably than PF_NOFREEZE,
So while improving PF_NOFREEZE handling is a worthwhile direction (and 
I’d be happy to explore that in a separate patch RFC 
[1]<https://lore.kernel.org/all/20250624115244.19260-1-zhangzihuan@kylinos.cn/>), 
this small patch keeps the logic minimal and avoids subtle corner cases. 
It also reduces unnecessary locking for zombie tasks, which can help 
when there are lots of them around.
[1]: 
https://lore.kernel.org/all/20250624115244.19260-1-zhangzihuan@kylinos.cn/
Thanks again for your insightful feedback — much appreciated.

Best regards,
Zihuan Zhang


  reply	other threads:[~2025-07-07  1:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 10:12 [PATCH v3 0/1] PM / Freezer: Skip zombie/dead processes to reduce Zihuan Zhang
2025-06-11 10:12 ` [PATCH v3 1/1] PM / Freezer: Skip zombie/dead processes to Zihuan Zhang
2025-07-03 14:15   ` Rafael J. Wysocki
2025-07-03 16:40     ` Peter Zijlstra
2025-07-03 17:15       ` Rafael J. Wysocki
2025-07-04  1:45         ` Zihuan Zhang
2025-07-04  8:19         ` Peter Zijlstra
2025-07-04  8:48           ` Zihuan Zhang
2025-07-04  9:21             ` Peter Zijlstra
2025-07-07  1:00               ` Zihuan Zhang [this message]
2025-07-07  8:42                 ` Peter Zijlstra
2025-07-08  0:56                   ` Zihuan Zhang
2025-07-16 16:16                   ` Oleg Nesterov

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=de7e327a-202c-4b28-b372-2d648c680dbe@kylinos.cn \
    --to=zhangzihuan@kylinos.cn \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=pavel@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    /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

all inboxes | Powered by JetHome®