Re: [PATCH v2 5/7] sched/fair: Increase weight bits for avg_vruntime
From: Vincent Guittot
Date: Mon Feb 23 2026 - 08:07:24 EST
On Mon, 23 Feb 2026 at 12:51, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Mon, Feb 23, 2026 at 11:56:33AM +0100, Vincent Guittot wrote:
> > On Thu, 19 Feb 2026 at 09:10, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > >
> > > Due to the zero_vruntime patch, the deltas are now a lot smaller and
> > > measurement with kernel-build and hackbench runs show about 45 bits
> > > used.
> > >
> > > This ensures avg_vruntime() tracks the full weight range, reducing
> > > numerical artifacts in reweight and the like.
> >
> > Instead of paranoid, would it be better to add WARN_ONCE ?
> >
> > I'm afraid that we will not notice any potential overflow without a
> > long study of the regression with SCHED_FEAT(PARANOID_AVG, false)
> >
> > Couldn't we add a cheaper WARN_ONCE (key > 2^50) in __sum_w_vruntime_add ?
> >
> > We should always have
> > key < 110ms (max slice+max tick) * nice_0 (2^20) / weight (2)
> > key < 2^46
> >
> > We can use 50 bits to get margin
> >
> > Weight is always less than 27bits and key*weight gives us 110ms (max
> > slice+max tick) * nice_0 (2^20) so we should never add more than 2^47
> > to ->sum_weight
> >
> > so a WARN_ONCE (cfs_rq->sum_weight > 2^63) should be enough
>
> Ha, I was >< close to pushing out these patches when I saw this.
>
> The thing is signed, so bit 63 is the sign bit, but I suppose we can
> test bit 62 like so:
Ah yes, I forgot that it's a signed value
>
> Let me go build and boot that.
>
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -679,9 +679,13 @@ static inline void
> __sum_w_vruntime_add(struct cfs_rq *cfs_rq, struct sched_entity *se)
> {
> unsigned long weight = avg_vruntime_weight(cfs_rq, se->load.weight);
> - s64 key = entity_key(cfs_rq, se);
> + s64 w_vruntime, key = entity_key(cfs_rq, se);
>
> - cfs_rq->sum_w_vruntime += key * weight;
> + w_vruntime = key * weight;
> +
> + WARN_ON_ONCE((w_vruntime >> 63) != (w_vruntime >> 62));
yes looks good
> +
> + cfs_rq->sum_w_vruntime += w_vruntime;
> cfs_rq->sum_weight += weight;
> }
>