Re: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()

From: Vlad Poenaru

Date: Wed Nov 25 2026 - 09:27:41 EST


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.

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.

I applied the same one-line change by hand to the v7.4-rc4 based kernel
that crashed. One soak run on it then completed all 200 iterations
without a crash.

So I think the fix should go through sched/urgent before v7.4 is released.

Tested-by: Vlad Poenaru <vlad.wing@xxxxxxxxx>