From nobody Fri Jul 24 22:17:21 2026 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1A77363C79 for ; Fri, 24 Jul 2026 04:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784866327; cv=none; b=nV32695LY+OWERtsOF0W5CK/fBfVymB9SrJgw2Lhx0P8pcHzeARZ/giNZqsCraxvHK0YEg5zV2cz4UGouP550Yxs3WaUf51auSxrUGi1mh+B7Ttt8Wx65LIa/x7hlWo/KT5nVl3533Iwfpj/OV4+voeXybXI6WNMa09zU53LVXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784866327; c=relaxed/simple; bh=9gUGwdJQriG9BhAwKkvxj4R4ihga2c7bsLePSYw7Bv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RMfETHLz9s2/0ScjJbzFASv9uP+GQobdM3QFFe+WdaJQIC0b858UvEeYthK0TVqpk6NzyjMJKrBDH/1vqI1S/56yL/K3Agw1wfgC3hr3f3o0YvmLeV1LeHblkbGLe0P+7UMLq9awGwgS8g8tO3DMD8ts/KGYqMn3wiRTuhUDuDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=omZh9vUV; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="omZh9vUV" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784866323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ckmJRpP0nZ2gtB6gT9YYriokoaTnVsOuxWDjymqwiGw=; b=omZh9vUVg1B1udU8FgYcVoVa8rZrRWcY6eolqNtwv2kZhWsk3sJLFMGXqfSGwNuiGBjo9Q eDMYYjCQfb9awZeY9TiI7o5VmfTr8RSQZEaaxN0NzDi06LLQ/9gsLU/AfOC662Jg2bgHVx HkhKNDfKRD96vnFmS9XU/pgtVSdrKsM= From: Tao Cui To: Johannes Weiner , Suren Baghdasaryan Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Tao Cui , 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 Message-ID: <20260724041146.510027-2-cui.tao@linux.dev> In-Reply-To: <20260724041146.510027-1-cui.tao@linux.dev> References: <20260724041146.510027-1-cui.tao@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Tao Cui window_update() estimates the stall growth inside a partially elapsed trigger window as growth +=3D win->prev_growth * remaining / win->size with `remaining =3D 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 =3D 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 --- 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; =20 remaining =3D win->size - elapsed; - growth +=3D div64_u64(win->prev_growth * remaining, win->size); + growth +=3D mul_u64_u64_div_u64(win->prev_growth, remaining, + win->size); } =20 return growth; --=20 2.43.0 From nobody Fri Jul 24 22:17:21 2026 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A5DC372685 for ; Fri, 24 Jul 2026 04:12:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784866330; cv=none; b=CREpUnTIo3iZs1I4OIK4ASlHnLjCx6HdljtDvPvi48hXQX1+nD39WjogPOhOMIM/4JbAa6jeCwHch4sptL4ivzNNIpyHOuWMqt40RYTk2tQ2Nou90nVfMLDb7ffsI0IEXhXmXib4ffSEQXVppv5lk7pAnWmBlACP/IMtLetKyVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784866330; c=relaxed/simple; bh=P+5MY7Jpbep6VLe7C28bZUbcGUSLt7mwPY7WgwrF4Fw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oj2nhS7OF2AOggq73tcKgFEwVsjdUYrcfN1hxHZAbSGGk/y0uJcS+RK0wwKBzBm58e79P4wOwDxDGxeu8zzSDOyoGTXIquc6o56mwGB6LO+WIo4pB3d9SA3O/GV2/deNdhosZ7vRBhUC7oOSr+4TsdDc7KpvBqU64yrdh4CHemg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=YZgMLs80; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="YZgMLs80" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784866326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y7edtw7YTHGS6Lj5/PpANDLWK1MJVNIzQVUCAAVArGI=; b=YZgMLs80bRziklsLkBaqG4Sg/MHzWdNNBZ7x3+srdz/3UrsXEDuS+sGeOH+0RbuTd/8MRi ZdybSG20iTQF0PCyf8ro1NjVK95nLCEryzyr4DWafmggL5GN+rGfvdyDODcj+JwrwilFOU nn5RVRNgOh8g/1WeNf99Q7x0wRDZY+A= From: Tao Cui To: Johannes Weiner , Suren Baghdasaryan Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Tao Cui , cui.tao@linux.dev Subject: [PATCH 2/2] sched/psi: convert trigger window/threshold to ns in u64 Date: Fri, 24 Jul 2026 12:11:46 +0800 Message-ID: <20260724041146.510027-3-cui.tao@linux.dev> In-Reply-To: <20260724041146.510027-1-cui.tao@linux.dev> References: <20260724041146.510027-1-cui.tao@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Tao Cui psi_trigger_create() scales the trigger threshold and window from microseconds to nanoseconds as t->threshold =3D threshold_us * NSEC_PER_USEC; t->win.size =3D window_us * NSEC_PER_USEC; NSEC_PER_USEC is 1000L, so on 32-bit the multiply is done in 32 bits and wraps for windows larger than ~4.29s (WINDOW_MAX_US is 10s): a 10s window is stored as ~1.41s and the trigger fires much too eagerly. Cast to u64 before multiplying. Fixes: 0e94682b73bf ("psi: introduce psi monitor") Signed-off-by: Tao Cui --- kernel/sched/psi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 6514b44222cf..7fbe9b94fafa 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1390,8 +1390,8 @@ struct psi_trigger *psi_trigger_create(struct psi_gro= up *group, char *buf, =20 t->group =3D group; t->state =3D state; - t->threshold =3D threshold_us * NSEC_PER_USEC; - t->win.size =3D window_us * NSEC_PER_USEC; + t->threshold =3D (u64)threshold_us * NSEC_PER_USEC; + t->win.size =3D (u64)window_us * NSEC_PER_USEC; window_reset(&t->win, sched_clock(), group->total[PSI_POLL][t->state], 0); =20 --=20 2.43.0