Skip to content

Commit e392427

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
Sebastian Andrzej Siewior
authored andcommitted
futex: Use a hashmask instead of hashsize
The global hash uses futex_hashsize to save the amount of the hash buckets that have been allocated during system boot. On each futex_hash() invocation this number is substracted by one to get the mask. This can be optimized by saving directly the mask avoiding the substraction on each futex_hash() invocation. Rename futex_hashsize to futex_hashmask and save the mask of the allocated hash map. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Waiman Long <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent d082ecb commit e392427

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)