[PATCH v6 8/8] futex: Use runtime constants for __futex_hash() hot path
Peter Zijlstra
peterz at infradead.org
Tue Jul 28 03:46:53 PDT 2026
On Tue, Jul 28, 2026 at 05:25:40AM +0000, K Prateek Nayak wrote:
> From: Peter Zijlstra <peterz at infradead.org>
>
> Runtime constify the read-only after init data __futex_shift(shift_32),
> __futex_mask(mask_32), and __futex_queues(ptr) used in __futex_hash()
> hot path to avoid referencing global variable.
>
> This also allows __futex_queues to be allocated dynamically to
> "nr_node_ids" slots instead of reserving config dependent MAX_NUMNODES
> (1 << CONFIG_NODES_SHIFT) worth of slots upfront.
>
> Runtime constants are initialized before their first access and
> runtime_const_init() provides necessary barrier to ensure subsequent
> accesses are not reordered against their initialization.
>
> No functional changes intended.
>
> [ prateek: Dynamically allocate __futex_queues, mark the global data
> __ro_after_init since they are constified after futex_init(). ]
>
> Link: https://patch.msgid.link/20260227161841.GH606826@noisy.programming.kicks-ass.net
> Reported-by: Sebastian Andrzej Siewior <bigeasy at linutronix.de> # MAX_NUMNODES bloat
> Signed-off-by: Peter Zijlstra <peterz at infradead.org>
> Reviewed-by: Charlie Jenkins <thecharlesjenkins at gmail.com>
> Tested-by: Charlie Jenkins <thecharlesjenkins at gmail.com>
> Signed-off-by: K Prateek Nayak <kprateek.nayak at amd.com>
> ---
> changelog v5..v6:
>
> o Picked up tags from Charlie. (Thanks a ton!)
>
> o Picked up Peter's S-o-b from his tree.
Right, so I also munged the Changelog in my tree to include those
benchmark results. I failed to actually push out those patches before
disappearing on holidays, but I recon I should refresh them patches and
re-munge the changelog?
> o Added a barrier after runtime_const_init() after to prevent compilers
> from re-ordering a later runtime const usage in the init function with
> their initialization. (Sashiko; Reported by Intel test robot with a
> GCC14 build).
> (https://lore.kernel.org/lkml/alNgNvhIkBfkGo1Y@xsang-OptiPlex-9020/)
More information about the linux-riscv
mailing list