[PATCH v2] sched/psi: Preserve PSI state on delayed dequeue
From: Shubhang Kaushik (Ampere)
Date: Wed Nov 11 2026 - 02:25:32 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxxx
---
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@xxxxxxxxxx>