[PATCH 1/2] sched/psi: Fix long-window growth interpolation

From: Guopeng Zhang

Date: Fri Jul 17 2026 - 06:30:40 EST


From: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>

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@xxxxxxxxxx>
---
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