Re: [PATCH 0/4] sched: Various reweight_entity() fixes

From: Vincent Guittot

Date: Thu Feb 12 2026 - 12:25:24 EST


On Thu, 12 Feb 2026 at 18:16, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Thu, Feb 12, 2026 at 12:59:43PM +0100, Peter Zijlstra wrote:
> > On Thu, Feb 12, 2026 at 01:13:30PM +0530, K Prateek Nayak wrote:
>
> > > Enqueue cfs_rq: depth(1) weight(2144337920) nr_queued(2045) sum_w_vruntime(18343811230990336) sum_weight(2144337920) zero_vruntime(18337852274) sum_shift(0) avg_vruntime(18337852274)
> > > Dequeue cfs_rq: depth(1) weight(2144337920) nr_queued(2045) sum_w_vruntime(1303379968) sum_weight(2143289344) zero_vruntime(18354971669) sum_shift(0) avg_vruntime(18354971669)
>
> After staring at waaay too many traces of my own, which confirm what
> you're seeing, but didn't want to make any sense either...
>
> ... I thinks I found it ...
>
> Note that sum_weight, that has _just_ flipped bit 31 and thus turned
> negative *if* it were a 32bit number. Every time, exactly at this point
> things started to go sideways.
>
> So I went looking for where this might be and I found the below.
>
> My latest run has passed 0x8000000/(1024*1024) = 2048 tasks and is still
> running. Numbers are still sane, fingers crossed.
>
>
> ---
>
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 5b1a2abb727e..de155be02411 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -797,7 +797,11 @@ u64 avg_vruntime(struct cfs_rq *cfs_rq)
> if (runtime < 0)
> runtime -= (weight - 1);
>
> +#ifndef CONFIG_64BIT
> delta = div_s64(runtime, weight);
> +#else
> + delta = runtime / weight;
> +#endif

Good catch

Don't we have the same problem with the div_s64 in place_entity ?

> } else if (curr) {
> /*
> * When there is but one element, it is the average.