mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kayra Cizmeci <kayracizmeci@gmail.com>
To: "Shubhang Kaushik (Ampere)" <sh@gentwo.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	 Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	 Shubhang Kaushik <shubhang@os.amperecomputing.com>,
	"Christopher Lameter (Ampere)" <cl@gentwo.org>,
	 John Stultz <jstultz@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH v2] sched/psi: Preserve PSI state on delayed dequeue
Date: Wed, 11 Nov 2026 12:30:28 +0300	[thread overview]
Message-ID: <avQfCeibnuffnZUE@scheduler.schedules> (raw)
In-Reply-To: <20261110-psi-delayed-deq-v2-1-17ac1688f0e9@gentwo.org>

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

      reply	other threads:[~2026-11-11  9:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  7:09 Shubhang Kaushik (Ampere)
2026-11-11  9:30 ` Kayra Cizmeci [this message]

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=avQfCeibnuffnZUE@scheduler.schedules \
    --to=kayracizmeci@gmail.com \
    --cc=bsegall@google.com \
    --cc=cl@gentwo.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sh@gentwo.org \
    --cc=shubhang@os.amperecomputing.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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

all inboxes | Powered by JetHome®