Use the hashlocal hashmap if provided.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/futex/core.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 7c97fc96f84a3..ee5a6902154c5 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -119,13 +119,18 @@ late_initcall(fail_futex_debugfs);
* @key: Pointer to the futex key for which the hash is calculated
*
* We hash on the keys returned from get_futex_key (see below) and return the
- * corresponding hash bucket in the global hash.
+ * corresponding hash bucket in the global hash. If the FUTEX is private and
+ * a local hash table is privated then this one is used.
*/
struct futex_hash_bucket *futex_hash(union futex_key *key)
{
+ struct futex_hash_table *fht;
u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
key->both.offset);
+ fht = current->futex_hash_table;
+ if (fht && (key->both.offset & (FUT_OFF_INODE | FUT_OFF_MMSHARED)) == 0)
+ return &fht->queues[hash & (fht->slots - 1)];
return &futex_queues[hash & (futex_hashsize - 1)];
}
--
2.45.2
On Sun, Oct 27, 2024 at 12:34:52AM +0200, Sebastian Andrzej Siewior wrote:
> Use the hashlocal hashmap if provided.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> kernel/futex/core.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/futex/core.c b/kernel/futex/core.c
> index 7c97fc96f84a3..ee5a6902154c5 100644
> --- a/kernel/futex/core.c
> +++ b/kernel/futex/core.c
> @@ -119,13 +119,18 @@ late_initcall(fail_futex_debugfs);
> * @key: Pointer to the futex key for which the hash is calculated
> *
> * We hash on the keys returned from get_futex_key (see below) and return the
> - * corresponding hash bucket in the global hash.
> + * corresponding hash bucket in the global hash. If the FUTEX is private and
> + * a local hash table is privated then this one is used.
> */
> struct futex_hash_bucket *futex_hash(union futex_key *key)
> {
> + struct futex_hash_table *fht;
> u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
> key->both.offset);
>
> + fht = current->futex_hash_table;
> + if (fht && (key->both.offset & (FUT_OFF_INODE | FUT_OFF_MMSHARED)) == 0)
> + return &fht->queues[hash & (fht->slots - 1)];
Perhaps add a helper like:
static inline bool futex_key_is_private(struct futex_key *key)
{
/*
* Relies on get_futex_key() to set either bit for shared
* futexes -- see comment with union futex_key.
*/
return !(key->both.offset & (FUT_OFF_INODE | FUT_OFF_MMSHARED));
}
On 2024-10-28 11:22:53 [+0100], Peter Zijlstra wrote:
> > struct futex_hash_bucket *futex_hash(union futex_key *key)
> > {
> > + struct futex_hash_table *fht;
> > u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4,
> > key->both.offset);
> >
> > + fht = current->futex_hash_table;
> > + if (fht && (key->both.offset & (FUT_OFF_INODE | FUT_OFF_MMSHARED)) == 0)
> > + return &fht->queues[hash & (fht->slots - 1)];
>
> Perhaps add a helper like:
>
> static inline bool futex_key_is_private(struct futex_key *key)
> {
> /*
> * Relies on get_futex_key() to set either bit for shared
> * futexes -- see comment with union futex_key.
> */
> return !(key->both.offset & (FUT_OFF_INODE | FUT_OFF_MMSHARED));
> }
Oki.
Sebastian
© 2016 - 2026 Red Hat, Inc.