Re: [PATCH v33 1/7] sched/psi: Preserve sleep-persistent PSI flags on off-CPU sleeping dequeues

From: K Prateek Nayak

Date: Mon Oct 26 2026 - 00:32:59 EST


Hello John,

On 10/24/2026 3:34 AM, John Stultz wrote:
> diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
> index ebe0a7765f98e..20820fe1021a1 100644
> --- a/kernel/sched/stats.h
> +++ b/kernel/sched/stats.h
> @@ -175,12 +175,28 @@ static inline void psi_dequeue(struct task_struct *p, int flags)
> * Do nothing here.
> *
> * In the SCHED_PROXY_EXECUTION case we may do sleeping
> - * dequeues that are not followed by a task switch, so check
> - * TSK_ONCPU is set to ensure the task switch is imminent.
> - * Otherwise clear the flags as usual.
> + * dequeues that are not followed by a task switch. If TSK_ONCPU
> + * is not set (meaning we already switched away while the task
> + * stayed on the rq as a blocked donor), handle the sleeping
> + * state transition here so sleep-persistent states (TSK_MEMSTALL,
> + * TSK_IOWAIT) are preserved.
> */
> - if ((flags & DEQUEUE_SLEEP) && (p->psi_flags & TSK_ONCPU))
> + if (flags & DEQUEUE_SLEEP) {
> + int clear = TSK_RUNNING, set = 0;

nit. You can declare these on top with clear set to p->psi_flags
and override them accordingly here ...

> +
> + if (p->psi_flags & TSK_ONCPU)
> + return;
> + if (p->se.sched_delayed)
> + return;
> +
> + if (p->in_memstall)
> + clear |= TSK_MEMSTALL_RUNNING;
> + if (p->in_iowait)
> + set |= TSK_IOWAIT;
> +
> + psi_task_change(p, clear, set);

That way, we can have a single psi_task_change(p, clear, set)
at the end instead of calling it here and doing an early
return.

> return;
> + }
>
> /*
> * When migrating a task to another CPU, clear all psi

--
Thanks and Regards,
Prateek