From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>,
Suren Baghdasaryan <surenb@google.com>,
Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
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>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] sched/psi: Fix long-window growth interpolation
Date: Fri, 17 Jul 2026 18:28:23 +0800 [thread overview]
Message-ID: <20260717102824.985950-2-guopeng.zhang@linux.dev> (raw)
In-Reply-To: <20260717102824.985950-1-guopeng.zhang@linux.dev>
From: Guopeng Zhang <zhangguopeng@kylinos.cn>
PSI trigger windows are stored in nanoseconds and can be up to 10
seconds, but window_update() stores the remaining interval in a u32.
For example, after 2 seconds have elapsed in a 10-second window, the
remaining 8,000,000,000 ns is truncated to 3,705,032,704 ns.
Making remaining a u64 avoids the truncation, but the multiplication
can still overflow before the division. Both win->prev_growth and
remaining can be close to 10,000,000,000, so their product can exceed
U64_MAX.
Store the remaining interval in a u64 and use
mul_u64_u64_div_u64() to calculate the interpolation without
overflowing the intermediate product.
Fixes: 0e94682b73bf ("psi: introduce psi monitor")
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
kernel/sched/psi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 4e152410653d..8e4df8b17c25 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -137,6 +137,7 @@
* sampling of the aggregate task states would be.
*/
#include <linux/sched/clock.h>
+#include <linux/math64.h>
#include <linux/workqueue.h>
#include <linux/psi.h>
#include "sched.h"
@@ -451,10 +452,11 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)
if (elapsed > win->size)
window_reset(win, now, value, growth);
else {
- u32 remaining;
+ u64 remaining;
remaining = win->size - elapsed;
- growth += div64_u64(win->prev_growth * remaining, win->size);
+ growth += mul_u64_u64_div_u64(win->prev_growth, remaining,
+ win->size);
}
return growth;
--
2.43.0
next prev parent reply other threads:[~2026-07-17 10:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 10:28 [PATCH 0/2] sched/psi: Fix trigger time arithmetic Guopeng Zhang
2026-07-17 10:28 ` Guopeng Zhang [this message]
2026-07-17 10:28 ` [PATCH 2/2] sched/psi: Fix overflow in trigger time conversion on 32-bit Guopeng 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=20260717102824.985950-2-guopeng.zhang@linux.dev \
--to=guopeng.zhang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=surenb@google.com \
--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