Re: [PATCH v8 03/15] futex: Add basic infrastructure for local task local hash.
From: Peter Zijlstra
Date: Mon Feb 03 2025 - 09:50:13 EST
On Mon, Feb 03, 2025 at 02:59:23PM +0100, Sebastian Andrzej Siewior wrote:
> struct futex_hash_bucket *futex_hash(union futex_key *key)
> {
> - u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
> - key->both.offset);
> + struct futex_hash_bucket *fhb;
> + u32 hash;
>
> + fhb = current->mm->futex_hash_bucket;
> + if (fhb && futex_key_is_private(key)) {
> + u32 hash_mask = current->mm->futex_hash_mask;
> +
> + hash = jhash2((u32 *)key,
> + offsetof(typeof(*key), both.offset) / 4,
> + key->both.offset);
> + return &fhb[hash & hash_mask];
> + }
> + hash = jhash2((u32 *)key,
> + offsetof(typeof(*key), both.offset) / 4,
> + key->both.offset);
> return &futex_queues[hash & (futex_hashsize - 1)];
> }
Having read this later patch, I would still prefer this to look like:
struct futex_hash_bucker *futex_hash(union futex_key *key)
{
struct futex_hash_bucket *fhb = current->mm->futex_hash_bucket;
u32 hash;
if (futex_key_is_private) {
// shorter jhash invocation;
} else {
hash = jhash2((u32 *)key,
offsetof(typeof(*key), both.offset) / 4,
key->both.offset);
}
if (fhb)
return fhb[hash & current->mm->futex_hash_mask];
return &futex_queues[hash & (futex_hashsize - 1)];
}
Because the shorter hash invocation only cares about being private, not
about having fhb.
Notably, I'm also still thikning about all that pending FUTEX2_NUMA
stuff.