From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Peter Zijlstra <peterz@infradead.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: "Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
linux-kernel@vger.kernel.org,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"André Almeida" <andrealmeid@igalia.com>
Subject: Re: [RFC PATCH] futex: Dynamically allocate futex_queues depending on nr_node_ids
Date: Mon, 2 Mar 2026 10:29:23 +0530 [thread overview]
Message-ID: <d1ade972-2614-4c25-b9ca-01750780847c@amd.com> (raw)
In-Reply-To: <20260227161841.GH606826@noisy.programming.kicks-ass.net>
Hello Peter, Sebastian,
On 2/27/2026 9:48 PM, Peter Zijlstra wrote:
> On Fri, Feb 27, 2026 at 08:29:03PM +0530, K Prateek Nayak wrote:
>
>>> Both will result in at least one extra deref/cacheline for each futex
>>> op, no?
>>
>> Ack but I was wondering if that penalty can be offset by the fact that
>> we no longer need to look at "nr_node_ids" in a separate cacheline?
>>
>> I ran futex bench enough time before posting to come to conclusion that
>> there isn't any noticeable regression - the numbers swung either ways
>> and I just took one set for comparison.
>>
>> Sebastian and I have been having a more philosophical discussion on that
>> CONFIG_NODES_SHIFT default but I guess as far as this patch is concerned,
>> the conclusion is we want to avoid an extra dereference in the fast-path
>> at the cost of a little bit extra space?
>
> Ooh, I just remebered, I've always wanted to apply Linus' runtime-const
> stuff to the futex thing.
I had no clue this existed! Nifty.
>
> Something like the below. But I'm not sure if it actually makes a
> difference these days :/
>
> But that can surely fix up the extra deref.
>
[..snip..]
> @@ -1983,10 +1986,17 @@ static int __init futex_init(void)
> hashsize = max(4, hashsize);
> hashsize = roundup_pow_of_two(hashsize);
> #endif
> - futex_hashshift = ilog2(hashsize);
> + __futex_mask = hashsize - 1;
> + __futex_shift = ilog2(hashsize);
> size = sizeof(struct futex_hash_bucket) * hashsize;
> order = get_order(size);
>
> + void *__futex_queues = &__futex_data.queues;
For __futex_queues, can we instead do:
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 8b58d9035e3a..6cefa0629849 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -48,15 +48,6 @@
#include "futex.h"
#include "../locking/rtmutex_common.h"
-/*
- * The base of the bucket array and its size are always used together
- * (after initialization only in futex_hash()), so ensure that they
- * reside in the same cacheline.
- */
-static struct {
- struct futex_hash_bucket *queues[MAX_NUMNODES];
-} __futex_data __read_mostly __aligned(2*sizeof(long));
-
static u32 __futex_mask;
static u32 __futex_shift;
static struct futex_hash_bucket **__futex_queues;
@@ -1991,12 +1982,14 @@ static int __init futex_init(void)
size = sizeof(struct futex_hash_bucket) * hashsize;
order = get_order(size);
- void *__futex_queues = &__futex_data.queues;
+ __futex_queues = kcalloc(nr_node_ids, sizeof(*__futex_queues), GFP_KERNEL);
runtime_const_init(shift, __futex_shift);
runtime_const_init(mask, __futex_mask);
runtime_const_init(ptr, __futex_queues);
+ BUG_ON(!futex_queues());
+
for_each_node(n) {
struct futex_hash_bucket *table;
---
My machine didn't crash right away on running perf bench futex so I'm
assuming this works?
Sebastian, I haven't found any evidence of static data being interleaved
across NUMA (at least on x86). Since kernel data is identity mapped, is
it even possible for a static array to be allocated interleaved during
boot unless the policy in the BIOS is set to interleaved?
If the static allocation is same as a kcalloc(GFP_KERNEL) from NUMA
standpoint, is the above feasible?
> +
> + runtime_const_init(shift, __futex_shift);
> + runtime_const_init(mask, __futex_mask);
> + runtime_const_init(ptr, __futex_queues);
> +
> for_each_node(n) {
> struct futex_hash_bucket *table;
>
--
Thanks and Regards,
Prateek
prev parent reply other threads:[~2026-03-02 4:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 10:13 K Prateek Nayak
2026-02-24 11:13 ` Sebastian Andrzej Siewior
2026-02-25 3:36 ` K Prateek Nayak
2026-02-25 7:39 ` Sebastian Andrzej Siewior
2026-02-25 8:51 ` K Prateek Nayak
2026-02-25 9:22 ` Sebastian Andrzej Siewior
2026-02-27 8:47 ` K Prateek Nayak
2026-02-27 15:15 ` Sebastian Andrzej Siewior
2026-02-27 16:04 ` K Prateek Nayak
2026-02-27 14:42 ` Peter Zijlstra
2026-02-27 14:59 ` K Prateek Nayak
2026-02-27 16:18 ` Peter Zijlstra
2026-02-27 17:12 ` Sebastian Andrzej Siewior
2026-02-27 17:18 ` Peter Zijlstra
2026-03-02 4:59 ` K Prateek Nayak [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d1ade972-2614-4c25-b9ca-01750780847c@amd.com \
--to=kprateek.nayak@amd.com \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®