* [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
@ 2026-11-23 0:12 Prabhakar
2026-11-23 8:06 ` K Prateek Nayak
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Prabhakar @ 2026-11-23 0:12 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak
Cc: linux-kernel, Prabhakar, Lad Prabhakar
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Commit 486c3d06b902 ("sched/fair: Avoid transient double accounting
for delayed tasks") changed the h_nr_runnable logic in
dequeue_hierarchy() from "set to 1 unless delayed" to "set to 0 if
delayed", but left the initialiser at 0:
int h_nr_runnable = 0;
...
if (se->sched_delayed)
h_nr_runnable = 0;
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.
Initialise h_nr_runnable to 1 so that only delayed tasks, which
set_delayed() has already accounted for, skip the decrement.
Fixes: 486c3d06b902 ("sched/fair: Avoid transient double accounting for delayed tasks")
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 731d78155e65..2d9d3d686261 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8294,7 +8294,7 @@ static void dequeue_hierarchy(struct task_struct *p, int flags)
struct sched_entity *se = &p->se;
bool task_throttled = flags & DEQUEUE_THROTTLE;
int h_nr_idle = task_has_idle_policy(p);
- int h_nr_runnable = 0;
+ int h_nr_runnable = 1;
struct cfs_rq *cfs_rq;
bool dequeue = true;
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
2026-11-23 0:12 [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy() Prabhakar
@ 2026-11-23 8:06 ` K Prateek Nayak
2026-11-23 8:10 ` Chen Yu
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: K Prateek Nayak @ 2026-11-23 8:06 UTC (permalink / raw)
To: Prabhakar, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider
Cc: linux-kernel, Prabhakar, Lad Prabhakar
Hello Prabhakar,
On 11/23/2026 5:42 AM, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Commit 486c3d06b902 ("sched/fair: Avoid transient double accounting
> for delayed tasks") changed the h_nr_runnable logic in
> dequeue_hierarchy() from "set to 1 unless delayed" to "set to 0 if
> delayed", but left the initialiser at 0:
>
> int h_nr_runnable = 0;
> ...
> if (se->sched_delayed)
> h_nr_runnable = 0;
>
> 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.
>
> Initialise h_nr_runnable to 1 so that only delayed tasks, which
> set_delayed() has already accounted for, skip the decrement.
>
> Fixes: 486c3d06b902 ("sched/fair: Avoid transient double accounting for delayed tasks")
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Good catch! Feel free to include:
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
> ---
> kernel/sched/fair.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 731d78155e65..2d9d3d686261 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8294,7 +8294,7 @@ static void dequeue_hierarchy(struct task_struct *p, int flags)
> struct sched_entity *se = &p->se;
> bool task_throttled = flags & DEQUEUE_THROTTLE;
> int h_nr_idle = task_has_idle_policy(p);
> - int h_nr_runnable = 0;
> + int h_nr_runnable = 1;
> struct cfs_rq *cfs_rq;
> bool dequeue = true;
>
--
Thanks and Regards,
Prateek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
2026-11-23 0:12 [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy() Prabhakar
2026-11-23 8:06 ` K Prateek Nayak
@ 2026-11-23 8:10 ` Chen Yu
2026-11-23 13:36 ` Christian Loehle
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Chen Yu @ 2026-11-23 8:10 UTC (permalink / raw)
To: Prabhakar
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, yi1.lai, linux-kernel,
Prabhakar, Lad Prabhakar
Hi Lad Prabhakar,
On Mon, Nov 23, 2026 at 12:12:13AM +0000, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Commit 486c3d06b902 ("sched/fair: Avoid transient double accounting
> for delayed tasks") changed the h_nr_runnable logic in
> dequeue_hierarchy() from "set to 1 unless delayed" to "set to 0 if
> delayed", but left the initialiser at 0:
>
> int h_nr_runnable = 0;
> ...
> if (se->sched_delayed)
> h_nr_runnable = 0;
>
> 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.
>
> Initialise h_nr_runnable to 1 so that only delayed tasks, which
> set_delayed() has already accounted for, skip the decrement.
>
> Fixes: 486c3d06b902 ("sched/fair: Avoid transient double accounting for delayed tasks")
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
Thanks for the fix,
Tested-by: Chen Yu <yu.c.chen@intel.com>
Would you mind also add:
Reported-by: kernel test robot <yi1.lai@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202611230853.e2e6401-lkp@intel.com
thanks,
Chenyu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
2026-11-23 0:12 [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy() Prabhakar
2026-11-23 8:06 ` K Prateek Nayak
2026-11-23 8:10 ` Chen Yu
@ 2026-11-23 13:36 ` Christian Loehle
2026-11-23 13:52 ` Alexey Charkov
2026-11-25 14:27 ` Vlad Poenaru
4 siblings, 0 replies; 6+ messages in thread
From: Christian Loehle @ 2026-11-23 13:36 UTC (permalink / raw)
To: Prabhakar, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak
Cc: linux-kernel, Prabhakar, Lad Prabhakar
On 11/23/26 00:12, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Commit 486c3d06b902 ("sched/fair: Avoid transient double accounting
> for delayed tasks") changed the h_nr_runnable logic in
> dequeue_hierarchy() from "set to 1 unless delayed" to "set to 0 if
> delayed", but left the initialiser at 0:
>
> int h_nr_runnable = 0;
> ...
> if (se->sched_delayed)
> h_nr_runnable = 0;
>
> 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.
>
> Initialise h_nr_runnable to 1 so that only delayed tasks, which
> set_delayed() has already accounted for, skip the decrement.
>
> Fixes: 486c3d06b902 ("sched/fair: Avoid transient double accounting for delayed tasks")
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
My Pixel6 tests found a ~3x power regression from 7.4-rc3 -> 7.4-rc4 with
both EAS on and EAS off (i.e. CAS), caused by
486c3d06b902 ("sched/fair: Avoid transient double accounting for delayed tasks").
This patch fixes it, thanks!
Tested-by: Christian Loehle <christian.loehle@arm.com>
> ---
> kernel/sched/fair.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 731d78155e65..2d9d3d686261 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8294,7 +8294,7 @@ static void dequeue_hierarchy(struct task_struct *p, int flags)
> struct sched_entity *se = &p->se;
> bool task_throttled = flags & DEQUEUE_THROTTLE;
> int h_nr_idle = task_has_idle_policy(p);
> - int h_nr_runnable = 0;
> + int h_nr_runnable = 1;
> struct cfs_rq *cfs_rq;
> bool dequeue = true;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
2026-11-23 0:12 [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy() Prabhakar
` (2 preceding siblings ...)
2026-11-23 13:36 ` Christian Loehle
@ 2026-11-23 13:52 ` Alexey Charkov
2026-11-25 14:27 ` Vlad Poenaru
4 siblings, 0 replies; 6+ messages in thread
From: Alexey Charkov @ 2026-11-23 13:52 UTC (permalink / raw)
To: Prabhakar
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, linux-kernel, Prabhakar,
Lad Prabhakar
On Mon, Nov 23, 2026 at 4:12 AM Prabhakar <prabhakar.csengg@gmail.com> wrote:
>
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Commit 486c3d06b902 ("sched/fair: Avoid transient double accounting
> for delayed tasks") changed the h_nr_runnable logic in
> dequeue_hierarchy() from "set to 1 unless delayed" to "set to 0 if
> delayed", but left the initialiser at 0:
>
> int h_nr_runnable = 0;
> ...
> if (se->sched_delayed)
> h_nr_runnable = 0;
>
> 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.
>
> Initialise h_nr_runnable to 1 so that only delayed tasks, which
> set_delayed() has already accounted for, skip the decrement.
>
> Fixes: 486c3d06b902 ("sched/fair: Avoid transient double accounting for delayed tasks")
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Thanks a lot for the fix! The offending commit forced my RK3576 board
to keep its little CPU cluster pinned at the top frequency even when
completely idle, and with your change applied it's now back to normal.
Tested-by: Alexey Charkov <alchark@flipper.net>
Best regards,
Alexey
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy()
2026-11-23 0:12 [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy() Prabhakar
` (3 preceding siblings ...)
2026-11-23 13:52 ` Alexey Charkov
@ 2026-11-25 14:27 ` Vlad Poenaru
4 siblings, 0 replies; 6+ messages in thread
From: Vlad Poenaru @ 2026-11-25 14:27 UTC (permalink / raw)
To: Prabhakar, Lad Prabhakar
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Chen Yu, Christian Loehle,
Alexey Charkov, Prabhakar, linux-kernel, kernel-team
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@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-25 14:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 0:12 [PATCH] sched/fair: Fix h_nr_runnable leak in dequeue_hierarchy() Prabhakar
2026-11-23 8:06 ` K Prateek Nayak
2026-11-23 8:10 ` Chen Yu
2026-11-23 13:36 ` Christian Loehle
2026-11-23 13:52 ` Alexey Charkov
2026-11-25 14:27 ` Vlad Poenaru
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®