Re: [PATCH] sched/fair: Avoid transient double accounting for delayed tasks
From: Peter Zijlstra
Date: Thu Nov 12 2026 - 06:19:47 EST
On Thu, Nov 12, 2026 at 08:34:47AM +0000, K Prateek Nayak wrote:
> When a task is delayed, h_nr_runnable is adjusted via set_delayed().
>
> A dequeue of delayed task with DEQUEUE_DELAYED would decrement
> cfs_rq->h_nr_runnable again in dequeue_hierarchy() and then correct it
> immediately in __dequeue_task() via clear_delayed().
>
> Adding:
>
> WARN_ON_ONCE(((int)cfs_rq->h_nr_runnable) < 0);
>
> in dequeue_hierarchy() after h_nr_runnable accounting is tripped
> reliably during early boot.
>
> Although the cfs_rq->h_nr_runnable accounting is transient, this
> incorrect value gets cached in se->runnable_weight and can affect PELT
> calculation until the next enqueue / dequeue adjusts the runnable
> weight.
>
> Similarly, a task enqueue should never reach enqueue_hierarchy()
> for just ENQUEUE_WAKEUP && se->sched_delayed. Wakeup of delayed tasks
> must couple ENQUEUE_DELAYED which gets correctly handled in
> enqueue_task_fair().
>
> Avoid incorrect accounting in __dequeue_task() and warn for
> incorrect wakeup flags if delayed tasks reaches enqueue with just
> ENQUEUE_WAKEUP.
>
> Fixes: 85570f10a4c6 ("sched/eevdf: Move to a single runqueue")
> Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Urgh, thanks!