]> git.ipfire.org Git - thirdparty/linux.git/commit
rqspinlock: Disable spinning for trylock fallback
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Fri, 28 Nov 2025 23:28:00 +0000 (23:28 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 29 Nov 2025 17:35:36 +0000 (09:35 -0800)
commit30dc2f7025fe461132595500c761075a250f0e16
tree3c84a9731080051dd50f4b5acc418aff64e94736
parent81d5a6a438595e46be191d602e5c2d6d73992fdc
rqspinlock: Disable spinning for trylock fallback

The original trylock fallback was inherited from qspinlock, and then
reused for the reentrant NMIs while the slow path is active. However,
under contention, it is very unlikely for the trylock to succeed in
taking the lock. In addition, a trylock also has no fairness guarantees,
and thus is prone to starvation issues under extreme scenarios.

The original qspinlock had no choice in terms of returning an error the
caller; if the node count was breached, it had to fall back to trylock
to attempt to take the lock. In case of rqspinlock, we do have the
option of returning to the user. Thus, simply attempt the trylock once,
and instead of spinning, return an error in case the lock cannot be
taken.

This ends up significantly reducing the time spent in the trylock
fallback, since we no longer wait for the timeout duration trying to
aimlessly acquire the lock when there's a high-probability that under
contention, it won't be available to us anyway.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20251128232802.1031906-5-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/rqspinlock.c