Re: [RFC PATCH] futex: Dynamically allocate futex_queues depending on nr_node_ids

From: Peter Zijlstra

Date: Fri Feb 27 2026 - 12:21:47 EST


On Fri, Feb 27, 2026 at 06:12:30PM +0100, Sebastian Andrzej Siewior wrote:
> On 2026-02-27 17:18:41 [+0100], Peter Zijlstra wrote:
> > Ooh, I just remebered, I've always wanted to apply Linus' runtime-const
> > stuff to the futex thing.
>
> I wasn't aware we have this, I did want to do/ have something like this.
>
> Need to look at this in detail but…
>
> > --- a/kernel/futex/core.c
> > +++ b/kernel/futex/core.c
> > @@ -439,14 +442,14 @@ __futex_hash(union futex_key *key, struct futex_private_hash *fph)
> > * NOTE: this isn't perfectly uniform, but it is fast and
> > * handles sparse node masks.
> > */
> > - node = (hash >> futex_hashshift) % nr_node_ids;
> > + node = runtime_const_shift_right_32(hash, __futex_shift) % nr_node_ids;
>
> getting rid of that div here would be the next step. If we could round
> it up to the next pow2 then we could avoid it. But I remember it did not
> show up in bench as much as I was thinking it would.

Right, modern x86 seems really rather good at division (unlike a few
years ago).

But yes, it would be nice to do better there.