From: Tao Cui <cui.tao@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>,
Suren Baghdasaryan <surenb@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, Tao Cui <cuitao@kylinos.cn>,
cui.tao@linux.dev
Subject: [PATCH 1/2] sched/psi: fix trigger window growth interpolation for large windows
Date: Fri, 24 Jul 2026 12:11:45 +0800 [thread overview]
Message-ID: <20260724041146.510027-2-cui.tao@linux.dev> (raw)
In-Reply-To: <20260724041146.510027-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
window_update() estimates the stall growth inside a partially elapsed
trigger window as
growth += win->prev_growth * remaining / win->size
with `remaining = win->size - elapsed`. The local `remaining` is a u32,
but win->size is a u64 and may be as large as WINDOW_MAX_US (10s = 10^10
ns), which exceeds UINT32_MAX (~4.29s). For trigger windows larger than
~4.29s the assignment truncates `remaining`, the linear interpolation
collapses, and growth is heavily underestimated.
For a 10s window polled once per second with prev_growth equal to a full
window of stall, the estimate one second in is ~1.4s instead of 10s. A
trigger configured as "some 5s 10s" then waits until the actual stall
reaches the threshold (~4s in) instead of firing as soon as the run-rate
predicts it (~1s in): a multi-second delay on the first window of a
stall.
Use a u64 `remaining` and mul_u64_u64_div_u64() for the product, which
also avoids the u64 overflow of `prev_growth * remaining` under heavy
pressure. This runs in update_triggers() at trigger-evaluation rate (at
most a few times per second), not the scheduler hot path, so the helper's
cost is immaterial.
Fixes: 0e94682b73bf ("psi: introduce psi monitor")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
kernel/sched/psi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 4e152410653d..6514b44222cf 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -451,10 +451,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-24 4:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 4:11 [PATCH 0/2] sched/psi: fix trigger window arithmetic Tao Cui
2026-07-24 4:11 ` Tao Cui [this message]
2026-07-24 4:11 ` [PATCH 2/2] sched/psi: convert trigger window/threshold to ns in u64 Tao Cui
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=20260724041146.510027-2-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=surenb@google.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