mariadb/extra
Marko Mäkelä bf0b82d24b MDEV-33515 log_sys.lsn_lock causes excessive context switching
The log_sys.lsn_lock is a very contended resource with a small
critical section in log_sys.append_prepare(). On many processor
microarchitectures, replacing the system call based log_sys.lsn_lock
with a pure spin lock would fare worse during high concurrency workloads,
wasting a significant amount of CPU cycles in the spin loop.

On other microarchitectures, we would see a significant amount of time
being spent in native_queued_spin_lock_slowpath() in the Linux kernel,
plus context switching between user and kernel address space. This was
pointed out by Steve Shaw from Intel Corporation.

Depending on the workload and the hardware implementation, it may be
useful to use a pure spin lock in log_sys.append_prepare().
We will introduce a parameter. The statement

	SET GLOBAL INNODB_LOG_SPIN_WAIT_DELAY=50;

would enable a spin lock that will execute that many MY_RELAX_CPU()
operations (such as the x86 PAUSE instruction) between successive
attempts of acquiring the spin lock. The use of a system call based
log_sys.lsn_lock (which is the default setting) can be enabled by

	SET GLOBAL INNODB_LOG_SPIN_WAIT_DELAY=0;

This patch will also introduce #ifdef LOG_LATCH_DEBUG
(part of cmake -DWITH_INNODB_EXTRA_DEBUG=ON) for more accurate
tracking of log_sys.latch ownership and reorganize the fields of
log_sys to improve the locality of reference and to reduce the
chances of false sharing.

When a spin lock is being used, it will be maintained in the
most significant bit of log_sys.buf_free. This is useful, because that is
one of the fields that is covered by the lock. For IA-32 or AMD64, we
implement the spin lock specially via log_t::lsn_lock_bts(), employing the
i386 LOCK BTS instruction. A straightforward std::atomic::fetch_or() would
translate into an inefficient loop around LOCK CMPXCHG.

mtr_t::spin_wait_delay: The value of innodb_log_spin_wait_delay.

mtr_t::finisher: Pointer to the currently used mtr_t::finish_write()
implementation. This allows to avoid introducing conditional branches.
We no longer invoke log_sys.is_pmem() at the mini-transaction level,
but we would do that in log_write_up_to().

mtr_t::finisher_update(): Update finisher when spin_wait_delay is
changed from or to 0 (the spin lock is changed to log_sys.lsn_lock or
vice versa).
2024-03-22 12:29:01 +02:00
..
aws_sdk MDEV-23539: aws key plugin - fails to build 2020-10-26 14:59:42 +11:00
mariabackup MDEV-33515 log_sys.lsn_lock causes excessive context switching 2024-03-22 12:29:01 +02:00
readline Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
wolfssl Return back wolfssl v5.6.6 and new CC changed by 6b2cd78695 2024-02-12 12:43:08 +01:00
charset2html.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
CMakeLists.txt MDEV-22552: mytop packaging 2021-10-25 12:15:49 +02:00
comp_err.c MDEV-30810 errmsg-utf8.txt no longer uses charsets 2023-03-10 08:53:58 +11:00
innochecksum.cc Merge branch '10.9' into 10.10 2023-08-05 20:34:09 +02:00
my_print_defaults.c Merge 10.6 into 10.11 2023-12-20 15:58:36 +02:00
mysql_waitpid.c Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00
mysqld_safe_helper.c mysqld_safe_help - remove warning 2017-04-30 15:06:01 +04:00
perror.c Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00
replace.c Merge 10.4 into 10.5 2022-07-01 14:42:02 +03:00
resolve_stack_dump.c MDEV-22189: Change error messages inside code to have mariadb instead of 2021-05-24 11:38:13 +05:30
resolveip.c Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00