Re: [PATCH v4] sched/fair: Replace random newidle_balance with Bresenham accumulator

From: Peter Zijlstra

Date: Fri Oct 30 2026 - 06:48:50 EST


On Fri, Oct 30, 2026 at 06:22:26PM +0800, Qing Wang wrote:
> On Fri, 30 Oct 2026 at 17:56, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > Funnily enough, treating this as an independent variable and using a
> > random number works and 'fixes' the slope change problems.
>
> Hi Peter,
>
> I explained this in the v3 thread: on a slope change, carrying
> newidle_window_pos over from the previous window only shifts the
> first allowed balance in the new-slope window (512 calls) earlier or
> later; subsequent balances are still uniformly spaced. So the
> initial value can be anything — it doesn't matter.

It does matter; you're rounding down. If you discard two fractions that
sum up to more than a whole, you've lost a call.

Let '/' be the integer division; then (3/2 + 3/2) = 2, but (3+3)/2 = 3.

IOW integer division (flooring) does not distribute.

The result here is less newidle calls than should have happened.

You cannot argue they are equal, you can argue the difference is
irrelevant. But so far you seem unable to see this distinction :-(

Also, the uniformity isn't a feature per se, another thing I called out
earlier. One reason why uniform distribution can be detrimental is if
two CPUs end up in a synchronized pattern, then you increase contention.

Now, again, there's plenty arguments to be had why that isn't a likely
issue in this case, but you cannot blindly state that uniform is better.