Re: [PATCH v4 03/11] futex: Allow automatic allocation of process wide futex hash.

Thomas Gleixner
2024-12-10T16:08:00Z

On Tue, Dec 03 2024 at 17:42, Sebastian Andrzej Siewior wrote:
> +static bool need_futex_hash_allocate_default(u64 clone_flags)
> +{
> + if ((clone_flags & (CLONE_THREAD | CLONE_VM)) != (CLONE_THREAD | CLONE_VM))
> + return false;
> + if (!thread_group_empty(current))
> + return false;
> + if (current->mm->futex_hash_bucket)
> + return false;

If you add an accessor like:

if (mm_get_futex_hash_bucket(current->mm))

then you can either #ifdef the futex muck in mm_struct or make it

struct mm_futex_hash_bucket {
#ifdef CONFIG_FUTEX
unsigned int futex_hash_mask;
struct futex_hash_bucket *futex_hash_bucket;
#endif
};

and avoid the #ifdeffery in mm_struct itself because the empty struct
occupies zero space.

The accessor and the other helpers allow the the compiler to optimize
all of it out for CONFIG_FUTEX=n.

Thanks,

tglx