From: David Hildenbrand <david@redhat.com>
To: Zihuan Zhang <zhangzihuan@kylinos.cn>,
rafael@kernel.org, len.brown@intel.com, pavel@kernel.org,
kees@kernel.org, mingo@redhat.com, peterz@infradead.org,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
akpm@linux-foundation.org, lorenzo.stoakes@oracle.com,
Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org,
surenb@google.com, mhocko@suse.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [RFC PATCH] PM: Optionally block user fork during freeze to improve performance
Date: Fri, 6 Jun 2025 09:20:27 +0200 [thread overview]
Message-ID: <0030581f-d50a-48f4-86f5-58e7883f705d@redhat.com> (raw)
In-Reply-To: <20250606062502.19607-1-zhangzihuan@kylinos.cn>
Hi,
On 06.06.25 08:25, Zihuan Zhang wrote:
> Currently, the freezer traverses all tasks to freeze them during
> system suspend or hibernation. If a user process forks during this
> window, the new child may escape freezing and require a second
> traversal or retry, adding non-trivial overhead.
>
> This patch introduces a CONFIG_PM_DISABLE_USER_FORK_DURING_FREEZE
Not sure if a Kconfig is really the right choice here ...
> option. When enabled, it prevents user processes from creating new
> processes (via fork/clone) during the freezing period. This guarantees
> a stable task list and avoids re-traversing the process list due to
> late-created user tasks, thereby improving performance.
Any performance numbers to back your claims?
>
> The restriction is only active during the window when the system is
> freezing user tasks. Once all tasks are frozen, or if the system aborts
> the suspend/hibernate process, the restriction is lifted.
> No kernel threads are affected, and kernel_create_* functions remain
> unrestricted.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> include/linux/suspend.h | 8 ++++++++
> kernel/fork.c | 6 ++++++
> kernel/power/Kconfig | 10 ++++++++++
> kernel/power/main.c | 44 +++++++++++++++++++++++++++++++++++++++++
> kernel/power/power.h | 4 ++++
> kernel/power/process.c | 7 +++++++
> 6 files changed, 79 insertions(+)
>
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index b1c76c8f2c82..2dd8b3eb50f0 100644
> --- a/include/linux/suspend.h
> +++ b/include/linux/suspend.h
> @@ -591,4 +591,12 @@ enum suspend_stat_step {
> void dpm_save_failed_dev(const char *name);
> void dpm_save_failed_step(enum suspend_stat_step step);
>
> +#ifdef CONFIG_PM_DISABLE_USER_FORK_DURING_FREEZE
> +extern bool pm_block_user_fork;
> +bool pm_should_block_fork(void);
> +bool pm_freeze_process_in_progress(void);
> +#else
> +static inline bool pm_should_block_fork(void) { return false; };
> +static inline bool pm_freeze_process_in_progress(void) { return false; };
> +#endif /* CONFIG_PM_DISABLE_USER_FORK_DURING_FREEZE */
> #endif /* _LINUX_SUSPEND_H */
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 1ee8eb11f38b..b0bd0206b644 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -105,6 +105,7 @@
> #include <uapi/linux/pidfd.h>
> #include <linux/pidfs.h>
> #include <linux/tick.h>
> +#include <linux/suspend.h>
>
> #include <asm/pgalloc.h>
> #include <linux/uaccess.h>
> @@ -2596,6 +2597,11 @@ pid_t kernel_clone(struct kernel_clone_args *args)
> trace = 0;
> }
>
> +#ifdef CONFIG_PM_DISABLE_USER_FORK_DURING_FREEZE
> + if (pm_should_block_fork() && !(current->flags & PF_KTHREAD))
> + return -EBUSY;
> +#endif
fork() is not documented to return EBUSY and for clone3() it's
documented to only happen in specific cases.
So user space is not prepared for that.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-06-06 7:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-06 6:25 Zihuan Zhang
2025-06-06 7:20 ` David Hildenbrand [this message]
2025-06-08 7:22 ` zhangzihuan
2025-06-08 15:50 ` Mateusz Guzik
2025-06-09 3:46 ` zhangzihuan
2025-06-06 8:22 ` Peter Zijlstra
2025-06-09 4:05 ` zhangzihuan
2025-06-10 10:50 ` David Hildenbrand
2025-06-13 2:37 ` Zihuan Zhang
2025-06-13 7:05 ` Michal Hocko
2025-06-16 3:46 ` Zihuan Zhang
2025-06-16 7:45 ` David Hildenbrand
2025-06-16 11:24 ` Michal Hocko
2025-06-18 11:30 ` Zihuan Zhang
2025-06-18 11:54 ` David Hildenbrand
2025-07-28 13:06 ` Zihuan Zhang
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=0030581f-d50a-48f4-86f5-58e7883f705d@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pm@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=pavel@kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=zhangzihuan@kylinos.cn \
/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