[RFC PATCH v2 0/7] futex: Use runtime constants for futex_hash computation
K Prateek Nayak
kprateek.nayak at amd.com
Sun Mar 15 22:23:54 PDT 2026
Use runtime consts for futex_mask, futex_queues, and futex_shift, all of
which is used in the __futex_hash() hot path. With runtime-const, the
futex_queues can be allocated dynamically to only nr_node_ids slots
which saves a bit of space and was the main motivation for v1.
To support the mask operation, runtime_const_mask_32() has been added
and implemented for all the architectures supporting runtime const. x86
implementation was provided by Peter in [1] and rest is me looking at
gcc disassembly with a helping hand from Claude to plumb the rest -
these are likely the bits that needs more review.
Apart from x86, which was build and boot tested on baremetal, all the
other architectures have been build and boot tested with cross-compile +
QEMU with some light sanity testing on each.
Reviews and feedback are much appreciated.
Patches are based on:
git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master
at commit 1def441ca008 ("Merge branch into tip/master: 'x86/tdx'") dated
15-03-2026.
Everyone has been Cc'd on the cover-letter and the futex bits for the
context. Respective arch maintainers, reviewers, and whoever got lucky
with get_maintainer.pl have been Cc'd on their respective arch specific
changes. Futex maintainers, reviewers, and the lists will be receiving
the whole series.
References:
[1] https://lore.kernel.org/all/20260227161841.GH606826@noisy.programming.kicks-ass.net/
---
changelog rfc v1..rfc v2:
o Use runtime constants to avoid the dereference overheads for
dynamically allocated futex_queues.
o arch/ side plumbings for runtime_const_mask_32()
rfc v1: https://lore.kernel.org/all/20260128101358.20954-1-kprateek.nayak@amd.com/
---
K Prateek Nayak (4):
arm64/runtime-const: Introduce runtime_const_mask_32()
arm64/runtime-const: Use aarch64_insn_patch_text_nosync() for patching
riscv/runtime-const: Introduce runtime_const_mask_32()
s390/runtime-const: Introduce runtime_const_mask_32()
Peter Zijlstra (3):
x86/runtime-const: Introduce runtime_const_mask_32()
asm-generic/runtime-const: Add dummy runtime_const_mask_32()
futex: Use runtime constants for __futex_hash() hot path
arch/arm64/include/asm/runtime-const.h | 34 +++++++++++++++------
arch/riscv/include/asm/runtime-const.h | 24 +++++++++++++++
arch/s390/include/asm/runtime-const.h | 19 ++++++++++++
arch/x86/include/asm/runtime-const.h | 14 +++++++++
include/asm-generic/runtime-const.h | 1 +
include/asm-generic/vmlinux.lds.h | 5 ++-
kernel/futex/core.c | 42 ++++++++++++++------------
7 files changed, 109 insertions(+), 30 deletions(-)
base-commit: 1def441ca0085042d41aa8614bee7269bd7e18ff
--
2.43.0
More information about the linux-riscv
mailing list