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 - 01:00:32 EST
Hello Peter,
On 10/24/2026 5:14 PM, Peter Zijlstra wrote:
> 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.
In this case, blocked donors going to sleep would need
to set the PSI flags accordingly (do what psi_sched_switch()
missed).
"p->se.sched_delayed" tasks would have already set those indicators
but can still arrive here from dequeue_task(SLEEP | DELAYED) of
sched_change_begin() - in all those cases, the dequeue flags will
also have DEQUEUE_DELAYED which can be used instead to bail out
early here.
Would that be okay?
>
>> +
>> + 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
>>
--
Thanks and Regards,
Prateek