Skip to content

Commit 0ae2062

Browse files
committed
Merge tag 'locking-futex-2025-03-23' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull futex update from Thomas Gleixner: "A single update for futexes: Use a precomputed mask for the hash computation instead of computing the mask from the size on every invocation" * tag 'locking-futex-2025-03-23' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: futex: Use a hashmask instead of hashsize
2 parents 0f40464 + e392427 commit 0ae2062

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

kernel/futex/core.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
*/
5151
static struct {
5252
struct futex_hash_bucket *queues;
53-
unsigned long hashsize;
53+
unsigned long hashmask;
5454
} __futex_data __read_mostly __aligned(2*sizeof(long));
5555
#define futex_queues (__futex_data.queues)
56-
#define futex_hashsize (__futex_data.hashsize)
56+
#define futex_hashmask (__futex_data.hashmask)
5757

5858

5959
/*
@@ -119,7 +119,7 @@ struct futex_hash_bucket *futex_hash(union futex_key *key)
119119
u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
120120
key->both.offset);
121121

122-
return &futex_queues[hash & (futex_hashsize - 1)];
122+
return &futex_queues[hash & futex_hashmask];
123123
}
124124

125125

@@ -1127,27 +1127,28 @@ void futex_exit_release(struct task_struct *tsk)
11271127

11281128
static int __init futex_init(void)
11291129
{
1130+
unsigned long hashsize, i;
11301131
unsigned int futex_shift;
1131-
unsigned long i;
11321132

11331133
#ifdef CONFIG_BASE_SMALL
1134-
futex_hashsize = 16;
1134+
hashsize = 16;
11351135
#else
1136-
futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus());
1136+
hashsize = roundup_pow_of_two(256 * num_possible_cpus());
11371137
#endif
11381138

11391139
futex_queues = alloc_large_system_hash("futex", sizeof(*futex_queues),
1140-
futex_hashsize, 0, 0,
1140+
hashsize, 0, 0,
11411141
&futex_shift, NULL,
1142-
futex_hashsize, futex_hashsize);
1143-
futex_hashsize = 1UL << futex_shift;
1142+
hashsize, hashsize);
1143+
hashsize = 1UL << futex_shift;
11441144

1145-
for (i = 0; i < futex_hashsize; i++) {
1145+
for (i = 0; i < hashsize; i++) {
11461146
atomic_set(&futex_queues[i].waiters, 0);
11471147
plist_head_init(&futex_queues[i].chain);
11481148
spin_lock_init(&futex_queues[i].lock);
11491149
}
11501150

1151+
futex_hashmask = hashsize - 1;
11511152
return 0;
11521153
}
11531154
core_initcall(futex_init);

0 commit comments

Comments
 (0)