Re: [PATCH v8 13/15] futex: Resize local futex hash table based on number of threads.

From: Sebastian Andrzej Siewior
Date: Fri Feb 07 2025 - 04:08:03 EST


On 2025-02-04 11:21:46 [+0100], Peter Zijlstra wrote:
> > + if (IS_ENABLED(CONFIG_BASE_SMALL)) {
> > + buckets = 2;
> > +
>
> Or... you just disable the local thing entirely for BASE_SMALL and have
> it fall back to the global hash.

If we don't assign a local hash on auto resize for CONFIG_BASE_SMALL
builds then we need to also disable PR_FUTEX_HASH_SET_SLOTS. Not against
it at all, just pointing out.

The reason is that there is at least one spot (exit_pi_state_list())
where I need a stable view of the hash. I ensure this by grabbing a
reference so this pointer does not change.
If this local hash is set to NULL then we are single threaded and it can
not be assigned. If we are multi threaded then the pointer is not NULL
and PR_FUTEX_HASH_SET_SLOTS based assignment will be delayed.
But if we are multi threaded and the local hash is set to NULL then it
could be assigned at which point the whole logic breaks.

Sebastian