In the futex-based implementation of InnoDB synchronization primitives srw_mutex::wait_and_lock() we are unnecessarily using a compare-and-swap loop for setting the HOLDER flag. We could use a fetch_add (to register the current thread as a waiter) followed by a fetch_or to set the flag. The value of a granted lock word with no waiting threads would change from HOLDER to HOLDER + 1.
Replacing the compare-and-swap loop seems to slightly improve performance in Sysbench oltp_update_index on my AMD64 based system, using a single NUMA node:
|threads||unpatched transactions/s||patched transactions/s|
We still use a compare-and-swap loop in ssux_lock_low::rd_lock_try() ever since
MDEV-24271. It used to be a greedy fetch_add() followed by a fetch_sub() back-off, but we observed starvation due to that.