* [PATCH v2] sched/psi: Preserve PSI state on delayed dequeue
@ 2026-11-11 7:09 Shubhang Kaushik (Ampere)
2026-11-11 9:30 ` Kayra Cizmeci
0 siblings, 1 reply; 2+ messages in thread
From: Shubhang Kaushik (Ampere) @ 2026-11-11 7:09 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Shubhang Kaushik,
Christopher Lameter (Ampere),
John Stultz, Johannes Weiner
Cc: linux-kernel, Ingo Molnar, Shubhang Kaushik (Ampere)
EEVDF can retain a blocked fair task as sched_delayed until it becomes
eligible for final removal.
On the initial sleep, psi_dequeue() does nothing because the task is
still TSK_ONCPU. psi_sched_switch(..., sleep=true) then converts the
task from runnable to sleeping, retaining TSK_IOWAIT and persistent
memory-stall state.
A delayed task can later be physically removed after it has switched
out via:
wait_task_inactive()
-> dequeue_task(DEQUEUE_SLEEP | DEQUEUE_DELAYED)
or:
switching_from_fair()
-> dequeue_task(DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK)
Commit c2ae8b0df2d1 ("sched/core: Fix psi_dequeue() for Proxy
Execution") made the DEQUEUE_SLEEP shortcut conditional on TSK_ONCPU
so that post-switch proxy-execution dequeues clear PSI state. However,
a delayed dequeue also occurs after the task switch, when its sleeping
PSI state has already been accounted by psi_sched_switch().
Consequently, psi_dequeue() clears TSK_IOWAIT for a still-sleeping
delayed task. A later wakeup attempts to clear TSK_IOWAIT again and can
trigger "psi: inconsistent task state".
Keep PSI state unchanged for DEQUEUE_DELAYED, as for DEQUEUE_SAVE.
Fixes: c2ae8b0df2d1 ("sched/core: Fix psi_dequeue() for Proxy Execution")
Signed-off-by: Shubhang Kaushik (Ampere) <sh@gentwo.org>
---
Testing on 80-core Ampere Altra:
- On v7.4-rc1 (6628e7d4c6b2), switching a delayed direct-I/O task
from SCHED_OTHER to SCHED_FIFO triggered:
"psi: inconsistent task state".
- With the patch applied, the identical test emitted no PSI warning.
Changes in v2:
- Correct the Fixes tag to c2ae8b0df2d1 ("sched/core: Fix psi_dequeue()
for Proxy Execution").
- Clarify that the regression was introduced when post-switch sleeping
dequeues began clearing PSI state.
Link to v1: https://lore.kernel.org/r/20261102-psi-delayed-deq-v1-1-8cd517c8fe51@gentwo.org
---
kernel/sched/stats.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index ebe0a7765f98e733af9f576033a0f8da65757f08..3e3f5cf4524d281816b01ba8165905fd1cbefc87 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -164,8 +164,13 @@ static inline void psi_dequeue(struct task_struct *p, int flags)
if (static_branch_likely(&psi_disabled))
return;
- /* Same runqueue, nothing changed for psi */
- if (flags & DEQUEUE_SAVE)
+ /*
+ * Saved dequeues retain task state across a dequeue/enqueue pair. A
+ * delayed dequeue completes a prior sleep dequeue after
+ * psi_sched_switch() accounted the runnable-to-sleeping transition.
+ * In both cases, keep the task's PSI state unchanged.
+ */
+ if (flags & (DEQUEUE_SAVE | DEQUEUE_DELAYED))
return;
/*
---
base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
change-id: 20261102-psi-delayed-deq-9535d7ffd138
Best regards,
--
Shubhang Kaushik (Ampere) <sh@gentwo.org>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] sched/psi: Preserve PSI state on delayed dequeue
2026-11-11 7:09 [PATCH v2] sched/psi: Preserve PSI state on delayed dequeue Shubhang Kaushik (Ampere)
@ 2026-11-11 9:30 ` Kayra Cizmeci
0 siblings, 0 replies; 2+ messages in thread
From: Kayra Cizmeci @ 2026-11-11 9:30 UTC (permalink / raw)
To: Shubhang Kaushik (Ampere)
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Shubhang Kaushik,
Christopher Lameter (Ampere),
John Stultz, Johannes Weiner, linux-kernel, Ingo Molnar
Hi Shubhang!
On Tue, Nov 10, 2026 at 11:09:59PM -0800, Shubhang Kaushik (Ampere) wrote:
> EEVDF can retain a blocked fair task as sched_delayed until it becomes
> eligible for final removal.
Yup.
>
> On the initial sleep, psi_dequeue() does nothing because the task is
> still TSK_ONCPU. psi_sched_switch(..., sleep=true) then converts the
> task from runnable to sleeping, retaining TSK_IOWAIT and persistent
> memory-stall state.
>
> A delayed task can later be physically removed after it has switched
> out via:
>
> wait_task_inactive()
> -> dequeue_task(DEQUEUE_SLEEP | DEQUEUE_DELAYED)
>
> or:
>
> switching_from_fair()
> -> dequeue_task(DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK)
>
> Commit c2ae8b0df2d1 ("sched/core: Fix psi_dequeue() for Proxy
> Execution") made the DEQUEUE_SLEEP shortcut conditional on TSK_ONCPU
> so that post-switch proxy-execution dequeues clear PSI state. However,
> a delayed dequeue also occurs after the task switch, when its sleeping
> PSI state has already been accounted by psi_sched_switch().
>
> Consequently, psi_dequeue() clears TSK_IOWAIT for a still-sleeping
> delayed task. A later wakeup attempts to clear TSK_IOWAIT again and can
> trigger "psi: inconsistent task state".
>
> Keep PSI state unchanged for DEQUEUE_DELAYED, as for DEQUEUE_SAVE.
So something like this happens:
We enter delayed dequeue. Then for some reason we leave the delayed
dequeue before we really wake up. Then we enter psi_dequeue() and we reset
the flags. Later when we really wake up and enqueue, we try to reset the
flags again.
With this fix, that doesn't happen since when we leave delayed dequeue
without really waking up we don't try to clear the flags.
>
> Fixes: c2ae8b0df2d1 ("sched/core: Fix psi_dequeue() for Proxy Execution")
> Signed-off-by: Shubhang Kaushik (Ampere) <sh@gentwo.org>
> ---
> Testing on 80-core Ampere Altra:
> - On v7.4-rc1 (6628e7d4c6b2), switching a delayed direct-I/O task
> from SCHED_OTHER to SCHED_FIFO triggered:
> "psi: inconsistent task state".
> - With the patch applied, the identical test emitted no PSI warning.
>
> Changes in v2:
> - Correct the Fixes tag to c2ae8b0df2d1 ("sched/core: Fix psi_dequeue()
> for Proxy Execution").
> - Clarify that the regression was introduced when post-switch sleeping
> dequeues began clearing PSI state.
>
> Link to v1: https://lore.kernel.org/r/20261102-psi-delayed-deq-v1-1-8cd517c8fe51@gentwo.org
> ---
> kernel/sched/stats.h | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
> index ebe0a7765f98e733af9f576033a0f8da65757f08..3e3f5cf4524d281816b01ba8165905fd1cbefc87 100644
> --- a/kernel/sched/stats.h
> +++ b/kernel/sched/stats.h
> @@ -164,8 +164,13 @@ static inline void psi_dequeue(struct task_struct *p, int flags)
> if (static_branch_likely(&psi_disabled))
> return;
>
> - /* Same runqueue, nothing changed for psi */
> - if (flags & DEQUEUE_SAVE)
> + /*
> + * Saved dequeues retain task state across a dequeue/enqueue pair. A
> + * delayed dequeue completes a prior sleep dequeue after
> + * psi_sched_switch() accounted the runnable-to-sleeping transition.
> + * In both cases, keep the task's PSI state unchanged.
> + */
> + if (flags & (DEQUEUE_SAVE | DEQUEUE_DELAYED))
> return;
>
> /*
>
> ---
> base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
> change-id: 20261102-psi-delayed-deq-9535d7ffd138
>
> Best regards,
> --
> Shubhang Kaushik (Ampere) <sh@gentwo.org>
>
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
Cheers,
Kayra
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-11 9:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 7:09 [PATCH v2] sched/psi: Preserve PSI state on delayed dequeue Shubhang Kaushik (Ampere)
2026-11-11 9:30 ` Kayra Cizmeci
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®