]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
sched/membarrier: Use per-CPU mutexes for targeted commands
authorAniket Gattani <aniketgattani@google.com>
Sun, 3 May 2026 21:22:03 +0000 (21:22 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 5 May 2026 10:50:48 +0000 (12:50 +0200)
commit89976cd73739dcb73745705a63ccc67a8be26cdf
treee2053441035aa8479da13373eb1b4a072764453b
parentb00192d78bb4f8b85d3545c7f86722610f088554
sched/membarrier: Use per-CPU mutexes for targeted commands

Currently, the membarrier system call uses a single global mutex
(`membarrier_ipi_mutex`) to serialize expedited commands. This causes
significant contention on large systems when multiple threads invoke
membarrier concurrently, even if they target different CPUs.

This contention becomes critical when combined with CFS bandwidth
throttling/unthrottling, during which interrupts can be disabled for
relatively long periods on target CPUs. If membarrier is waiting for a
response from such a CPU, it holds the global mutex, blocking all other
membarrier calls on the system. This cascade effect can lead to hard
lockups when thousands of threads stall waiting for the mutex.

Optimize `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` when a specific CPU is
targeted by introducing per-CPU mutexes. Broadcast commands and commands
without a specific CPU target continue to use the global mutex.

This prevents the cascade lockup scenario. As measured by the stress test
introduced in the subsequent patch, on an AMD Turin machine with 384 CPUs
(2 NUMA nodes with SMT=2), this optimization yields 200x more
throughput.

Signed-off-by: Aniket Gattani <aniketgattani@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260503212205.3714217-2-aniketgattani@google.com
kernel/sched/membarrier.c