Files
linux/include/asm-generic
Peter Zijlstra b78b0b6582 futex: Use runtime constants for __futex_hash() hot path
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.

perf bench futex on a 3rd Gen EPYC (2 x 64C/128T):

+----------------+-----------+-----------+-----------+--------------+
| Benchmark      | Kernel 1  | Kernel 2  |   Unit    | % Improvement|
|                |  (avg/5)  |  (avg/5)  |           | (K2 vs K1)   |
+----------------+-----------+-----------+-----------+--------------+
| Wake-parallel  |  0.01614  |  0.00456  |    ms     |   +71.75%    |
| Requeue        |  0.26394  |  0.24644  |    ms     |    +6.63%    |
| Lock-pi        |     34.0  |     57.2  |  ops/sec  |   +68.24%    |
+----------------+-----------+-----------+-----------+--------------+

Performance testing on a 144-thread Intel(R) Xeon(R) CPU E7-8890 v3 (4 NUMA nodes):

+-------------------------------------------------------------+
| perf bench futex hash -b 0                                  |
+----------------------+------------+------------+------------+
| Configuration        | As-is      | Patched    | Delta      |
+----------------------+------------+------------+------------+
| 1 thread, 1 futex    |  6,449,632 |  6,532,004 |   +1.28%   |
| 144 threads, 1024 fx |  2,111,486 |  2,139,685 |   +1.34%   |
+----------------------+------------+------------+------------+i

  [ prateek: Dynamically allocate __futex_queues, mark the global data
    __ro_after_init since they are constified after futex_init(). ]

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> # MAX_NUMNODES bloat
Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Link: https://patch.msgid.link/20260227161841.GH606826@noisy.programming.kicks-ass.net
Link: https://patch.msgid.link/20260728052540.4728-9-kprateek.nayak@amd.com
2026-07-29 13:17:52 +02:00
..
2022-02-25 09:36:06 +01:00
2023-02-13 22:13:29 +01:00
2025-11-24 20:23:25 +01:00
2023-12-15 16:25:55 -08:00
2024-01-17 17:52:29 -08:00
2024-09-01 20:26:13 -07:00
2025-07-08 18:35:52 +01:00
2024-09-03 21:15:32 -07:00
2022-07-22 17:34:57 -05:00
2024-11-11 07:33:20 -08:00
2025-02-18 10:16:00 +01:00
2024-11-11 07:33:20 -08:00
2024-11-11 21:51:42 +01:00