From: "zhidao su (Xiaomi)" <soolaugust@gmail.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Kees Cook <kees@kernel.org>,
Felix Moessbauer <felix.moessbauer@siemens.com>,
Thomas Gleixner <tglx@kernel.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
"zhidao su (Xiaomi)" <soolaugust@gmail.com>
Subject: [PATCH] sched: Preserve timer slack default across RT reset-on-fork
Date: Mon, 22 Jun 2026 10:50:06 +0800 [thread overview]
Message-ID: <20260622025006.614695-1-soolaugust@gmail.com> (raw)
RT and deadline policies force timer_slack_ns to zero while a task runs
under the realtime policy. The original slack value is kept in
default_timer_slack_ns so it can be restored when the task returns to a
normal policy.
copy_process() initializes the child's default_timer_slack_ns from
current->timer_slack_ns. For an RT/DL parent this copies the temporary
zero value into the child's default. If the parent also uses
SCHED_RESET_ON_FORK, sched_fork() resets the child to SCHED_NORMAL and
restores timer_slack_ns from that already-poisoned default, leaving the
child with zero slack.
Preserve current->default_timer_slack_ns when current->timer_slack_ns is
zero so reset-on-fork children can restore a real default slack value.
Fixes: ed4fb6d7ef68 ("hrtimer: Use and report correct timerslack values for realtime tasks")
Signed-off-by: zhidao su (Xiaomi) <soolaugust@gmail.com>
---
kernel/fork.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index addc555a1077..39db7502379b 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2196,7 +2196,14 @@ __latent_entropy struct task_struct *copy_process(
retval = -EAGAIN;
#endif
- p->default_timer_slack_ns = current->timer_slack_ns;
+ /*
+ * RT/DL tasks run with timer_slack_ns forced to zero, but their
+ * default_timer_slack_ns still carries the value to restore when
+ * returning to a normal policy. Preserve that default across fork so
+ * SCHED_RESET_ON_FORK children can restore a real slack value.
+ */
+ p->default_timer_slack_ns = current->timer_slack_ns ?:
+ current->default_timer_slack_ns;
#ifdef CONFIG_PSI
p->psi_flags = 0;
base-commit: e771677c937da5808f7b6c1f0e4a97ec1a84f8a8
--
2.43.0
reply other threads:[~2026-06-22 2:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260622025006.614695-1-soolaugust@gmail.com \
--to=soolaugust@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=felix.moessbauer@siemens.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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