On Sun, Aug 17, 2025 at 4:34 PM Thomas Munro <thomas.mu...@gmail.com> wrote: > Or if you don't like those odds, maybe it'd be OK to keep % but use it > rarely and without the CAS that can fail.
... or if we wanted to try harder to avoid %, could we relegate it to the unlikely CLOCK-went-all-the-way-around-again-due-to-unlucky-scheduling case, but use subtraction for the expected periodic overshoot? if (hand >= NBuffers) { hand = hand < Nbuffers * 2 ? hand - NBuffers : hand % NBuffers; /* Base value advanced by backend that overshoots by one tick. */ if (hand == 0) pg_atomic_fetch_add_u64(&StrategyControl->ticks_base, NBuffers); }