RE: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
From: Prabhakar Mahadev Lad
Date: Wed Nov 25 2026 - 09:43:32 EST
Hi Vlad,
> From: Vlad Poenaru <vlad.wing@xxxxxxxxx>
> Sent: 25 November 2026 14:27
> To: Prabhakar <prabhakar.csengg@xxxxxxxxx>; Prabhakar Mahadev Lad
> <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>; Peter Zijlstra <peterz@xxxxxxxxxxxxx>;
> Juri Lelli <juri.lelli@xxxxxxxxxx>; Vincent Guittot
> <vincent.guittot@xxxxxxxxxx>; Dietmar Eggemann <dietmar.eggemann@xxxxxxx>;
> Steven Rostedt <rostedt@xxxxxxxxxxx>; Ben Segall <bsegall@xxxxxxxxxx>; Mel
> Gorman <mgorman@xxxxxxx>; Valentin Schneider <vschneid@xxxxxxxxxx>; K
> Prateek Nayak <kprateek.nayak@xxxxxxx>; Chen Yu <yu.c.chen@xxxxxxxxx>;
> Christian Loehle <christian.loehle@xxxxxxx>; Alexey Charkov
> <alchark@xxxxxxxxxxx>; Prabhakar <prabhakar.csengg+renesas@xxxxxxxxx>;
> linux-kernel@xxxxxxxxxxxxxxx; kernel-team@xxxxxxxx
> Subject: Re: [PATCH] sched/fair: Fix h_nr_runnable leak in
> dequeue_hierarchy()
>
> [You don't often get email from vlad.wing@xxxxxxxxx. Learn why this is
> important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On Mon, Nov 23, 2026 at 12:12:13AM +0000, Prabhakar wrote:
> > h_nr_runnable is therefore always 0, so dequeuing a task that is not
> > delayed no longer decrements cfs_rq->h_nr_runnable. The count only
> > grows, which inflates se->runnable_weight and skews PELT runnable_avg
> > and load balancing.
>
> The leak also crashes machines. In Meta's kernel testing, a one-hour
> stress-ng soak on 176-CPU x86_64 machines hits a divide error on our
> internal kernels based on v7.4-rc4:
>
> Oops: divide error: 0000 [#1] SMP NOPTI
> RIP: 0010:update_load_avg+0x267/0x800
> Call Trace:
> task_tick_fair
> hrtick
> __hrtimer_run_queues
> hrtimer_interrupt
>
> 15 of the 16 machines that ran the soak on these kernels crashed this way,
> and the 16th left no crash record. None of the soak runs on
> v7.4-rc3 based kernels crashed.
>
> The divisor in update_tg_cfs_load() is
> scale_load_down(gcfs_rq->load.weight) truncated to u32. That weight was
> 0xfff8000000000000, so the u32 divisor is 0. Once the leaked count pushes
> tg->runnable_avg >> 10 past INT_MAX, tg_tasks() returns a negative int.
> calc_concur_shares() then gives clamp_t() a negative upper bound, and that
> becomes the group entity weight.
>
Thank you for testing.
> This patch is based on sched/core and does not apply to sched/urgent or to
> Linus' tree, where 486c3d06b902 ("sched/fair: Avoid transient double
> accounting for delayed tasks") is part of v7.4-rc4. In those trees the
> h_nr_runnable line comes before the h_nr_idle line.
>
@Ingo please let me know on which branch should I rebase this patch.
Cheers,
Prabhakar