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

From: Peter Zijlstra

Date: Sat Oct 24 2026 - 07:44:50 EST


On Fri, Oct 23, 2026 at 10:04:12PM +0000, 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;
> +
> + if (p->psi_flags & TSK_ONCPU)
> + return;
> + if (p->se.sched_delayed)
> + return;

Must this really be sched_delayed, that is, cannot p->is_blocked be used
here? I'm trying to push sched_delayed into fair.c if at all possible.

> +
> + if (p->in_memstall)
> + clear |= TSK_MEMSTALL_RUNNING;
> + if (p->in_iowait)
> + set |= TSK_IOWAIT;
> +
> + psi_task_change(p, clear, set);
> return;
> + }
>
> /*
> * When migrating a task to another CPU, clear all psi
> --
> 2.56.0.257.gf7497c7d27-goog
>