Re: [PATCH v4 08/11] futex: Resize futex hash table based on number of threads.

From: Thomas Gleixner
Date: Fri Dec 06 2024 - 04:27:33 EST


On Tue, Dec 03 2024 at 17:42, Sebastian Andrzej Siewior wrote:
> int futex_hash_allocate_default(void)
> {
> - return futex_hash_allocate(0);
> + unsigned int threads;
> + unsigned int buckets;
> + unsigned int current_buckets = 0;
> + struct futex_hash_bucket_private *hb_p;

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#variable-declarations

> +
> + if (!current->mm)
> + return 0;
> +
> + scoped_guard(rcu) {
> + threads = get_nr_threads(current);
> + hb_p = rcu_dereference(current->mm->futex_hash_bucket);
> + if (hb_p) {
> + if (hb_p->slots_invariant)
> + return 0;
> + current_buckets = hb_p->hash_mask + 1;
> + }
> + }
> +
> + buckets = roundup_pow_of_two(4 * threads);
> + buckets = max(buckets, 16);
> + buckets = min(buckets, futex_default_max_buckets);
> + if (current_buckets > buckets)

>= ?

Thanks,

tglx