* [PATCH] futex: Use a hashmask instead of hashsize.
@ 2025-02-26 9:10 Sebastian Andrzej Siewior
2025-02-26 14:37 ` Waiman Long
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-02-26 9:10 UTC (permalink / raw)
To: Thomas Gleixner
Cc: linux-kernel, André Almeida, Darren Hart, Davidlohr Bueso,
Ingo Molnar, Juri Lelli, Peter Zijlstra, Valentin Schneider,
Waiman Long
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 <bigeasy@linutronix.de>
---
Split from the "local hash" series.
kernel/futex/core.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 3db8567f5a44e..cca15859a50be 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -50,10 +50,10 @@
*/
static struct {
struct futex_hash_bucket *queues;
- unsigned long hashsize;
+ unsigned long hashmask;
} __futex_data __read_mostly __aligned(2*sizeof(long));
#define futex_queues (__futex_data.queues)
-#define futex_hashsize (__futex_data.hashsize)
+#define futex_hashmask (__futex_data.hashmask)
/*
@@ -119,7 +119,7 @@ struct futex_hash_bucket *futex_hash(union futex_key *key)
u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
key->both.offset);
- return &futex_queues[hash & (futex_hashsize - 1)];
+ return &futex_queues[hash & futex_hashmask];
}
@@ -1127,27 +1127,28 @@ void futex_exit_release(struct task_struct *tsk)
static int __init futex_init(void)
{
+ unsigned long hashsize, i;
unsigned int futex_shift;
- unsigned long i;
#ifdef CONFIG_BASE_SMALL
- futex_hashsize = 16;
+ hashsize = 16;
#else
- futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus());
+ hashsize = roundup_pow_of_two(256 * num_possible_cpus());
#endif
futex_queues = alloc_large_system_hash("futex", sizeof(*futex_queues),
- futex_hashsize, 0, 0,
+ hashsize, 0, 0,
&futex_shift, NULL,
- futex_hashsize, futex_hashsize);
- futex_hashsize = 1UL << futex_shift;
+ hashsize, hashsize);
+ hashsize = 1UL << futex_shift;
- for (i = 0; i < futex_hashsize; i++) {
+ for (i = 0; i < hashsize; i++) {
atomic_set(&futex_queues[i].waiters, 0);
plist_head_init(&futex_queues[i].chain);
spin_lock_init(&futex_queues[i].lock);
}
+ futex_hashmask = hashsize - 1;
return 0;
}
core_initcall(futex_init);
--
2.47.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] futex: Use a hashmask instead of hashsize.
2025-02-26 9:10 [PATCH] futex: Use a hashmask instead of hashsize Sebastian Andrzej Siewior
@ 2025-02-26 14:37 ` Waiman Long
2025-02-26 15:11 ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-02-27 1:54 ` [PATCH] " André Almeida
2 siblings, 0 replies; 4+ messages in thread
From: Waiman Long @ 2025-02-26 14:37 UTC (permalink / raw)
To: Sebastian Andrzej Siewior, Thomas Gleixner
Cc: linux-kernel, André Almeida, Darren Hart, Davidlohr Bueso,
Ingo Molnar, Juri Lelli, Peter Zijlstra, Valentin Schneider
On 2/26/25 4:10 AM, Sebastian Andrzej Siewior wrote:
> 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 <bigeasy@linutronix.de>
> ---
>
> Split from the "local hash" series.
>
> kernel/futex/core.c | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/futex/core.c b/kernel/futex/core.c
> index 3db8567f5a44e..cca15859a50be 100644
> --- a/kernel/futex/core.c
> +++ b/kernel/futex/core.c
> @@ -50,10 +50,10 @@
> */
> static struct {
> struct futex_hash_bucket *queues;
> - unsigned long hashsize;
> + unsigned long hashmask;
> } __futex_data __read_mostly __aligned(2*sizeof(long));
> #define futex_queues (__futex_data.queues)
> -#define futex_hashsize (__futex_data.hashsize)
> +#define futex_hashmask (__futex_data.hashmask)
>
>
> /*
> @@ -119,7 +119,7 @@ struct futex_hash_bucket *futex_hash(union futex_key *key)
> u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
> key->both.offset);
>
> - return &futex_queues[hash & (futex_hashsize - 1)];
> + return &futex_queues[hash & futex_hashmask];
> }
>
>
> @@ -1127,27 +1127,28 @@ void futex_exit_release(struct task_struct *tsk)
>
> static int __init futex_init(void)
> {
> + unsigned long hashsize, i;
> unsigned int futex_shift;
> - unsigned long i;
>
> #ifdef CONFIG_BASE_SMALL
> - futex_hashsize = 16;
> + hashsize = 16;
> #else
> - futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus());
> + hashsize = roundup_pow_of_two(256 * num_possible_cpus());
> #endif
>
> futex_queues = alloc_large_system_hash("futex", sizeof(*futex_queues),
> - futex_hashsize, 0, 0,
> + hashsize, 0, 0,
> &futex_shift, NULL,
> - futex_hashsize, futex_hashsize);
> - futex_hashsize = 1UL << futex_shift;
> + hashsize, hashsize);
> + hashsize = 1UL << futex_shift;
>
> - for (i = 0; i < futex_hashsize; i++) {
> + for (i = 0; i < hashsize; i++) {
> atomic_set(&futex_queues[i].waiters, 0);
> plist_head_init(&futex_queues[i].chain);
> spin_lock_init(&futex_queues[i].lock);
> }
>
> + futex_hashmask = hashsize - 1;
> return 0;
> }
> core_initcall(futex_init);
LGTM
Reviewed-by: Waiman Long <longman@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip: locking/futex] futex: Use a hashmask instead of hashsize
2025-02-26 9:10 [PATCH] futex: Use a hashmask instead of hashsize Sebastian Andrzej Siewior
2025-02-26 14:37 ` Waiman Long
@ 2025-02-26 15:11 ` tip-bot2 for Sebastian Andrzej Siewior
2025-02-27 1:54 ` [PATCH] " André Almeida
2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-02-26 15:11 UTC (permalink / raw)
To: linux-tip-commits
Cc: Sebastian Andrzej Siewior, Thomas Gleixner, Waiman Long, x86,
linux-kernel
The following commit has been merged into the locking/futex branch of tip:
Commit-ID: e3924279e5164d821fa2cbcf0c15e7345cb3508e
Gitweb: https://git.kernel.org/tip/e3924279e5164d821fa2cbcf0c15e7345cb3508e
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Wed, 26 Feb 2025 10:10:57 +01:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 26 Feb 2025 16:07:59 +01:00
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 <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Waiman Long <longman@redhat.com>
Link: https://lore.kernel.org/all/20250226091057.bX8vObR4@linutronix.de
---
kernel/futex/core.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 3db8567..cca1585 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -50,10 +50,10 @@
*/
static struct {
struct futex_hash_bucket *queues;
- unsigned long hashsize;
+ unsigned long hashmask;
} __futex_data __read_mostly __aligned(2*sizeof(long));
#define futex_queues (__futex_data.queues)
-#define futex_hashsize (__futex_data.hashsize)
+#define futex_hashmask (__futex_data.hashmask)
/*
@@ -119,7 +119,7 @@ struct futex_hash_bucket *futex_hash(union futex_key *key)
u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
key->both.offset);
- return &futex_queues[hash & (futex_hashsize - 1)];
+ return &futex_queues[hash & futex_hashmask];
}
@@ -1127,27 +1127,28 @@ void futex_exit_release(struct task_struct *tsk)
static int __init futex_init(void)
{
+ unsigned long hashsize, i;
unsigned int futex_shift;
- unsigned long i;
#ifdef CONFIG_BASE_SMALL
- futex_hashsize = 16;
+ hashsize = 16;
#else
- futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus());
+ hashsize = roundup_pow_of_two(256 * num_possible_cpus());
#endif
futex_queues = alloc_large_system_hash("futex", sizeof(*futex_queues),
- futex_hashsize, 0, 0,
+ hashsize, 0, 0,
&futex_shift, NULL,
- futex_hashsize, futex_hashsize);
- futex_hashsize = 1UL << futex_shift;
+ hashsize, hashsize);
+ hashsize = 1UL << futex_shift;
- for (i = 0; i < futex_hashsize; i++) {
+ for (i = 0; i < hashsize; i++) {
atomic_set(&futex_queues[i].waiters, 0);
plist_head_init(&futex_queues[i].chain);
spin_lock_init(&futex_queues[i].lock);
}
+ futex_hashmask = hashsize - 1;
return 0;
}
core_initcall(futex_init);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] futex: Use a hashmask instead of hashsize.
2025-02-26 9:10 [PATCH] futex: Use a hashmask instead of hashsize Sebastian Andrzej Siewior
2025-02-26 14:37 ` Waiman Long
2025-02-26 15:11 ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
@ 2025-02-27 1:54 ` André Almeida
2 siblings, 0 replies; 4+ messages in thread
From: André Almeida @ 2025-02-27 1:54 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-kernel, Darren Hart, Davidlohr Bueso, Ingo Molnar,
Juri Lelli, Peter Zijlstra, Valentin Schneider, Waiman Long,
Thomas Gleixner
Em 26/02/2025 06:10, Sebastian Andrzej Siewior escreveu:
> 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 <bigeasy@linutronix.de>
Reviewed-by: André Almeida <andrealmeid@igalia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-27 1:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-26 9:10 [PATCH] futex: Use a hashmask instead of hashsize Sebastian Andrzej Siewior
2025-02-26 14:37 ` Waiman Long
2025-02-26 15:11 ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-02-27 1:54 ` [PATCH] " André Almeida
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®