commit f40d1ce04231e9777a624180646736159dcd2f6b Author: zhangxizhe Date: Mon Mar 18 10:43:33 2024 +0800 Align Delegate::lock to 64 Background ========== Every transaction THD will call the corresponding method (e.g. before_commit()) of `transaction_delegate` at different stages to execute the callback function of the registered Observers. This part of the code will be protected by calling `Delegate:read_lock()`, which uses a `pthread_rwlock_t` (64B) RW lock. However, the memory allocation of `transaction_delegate` is aligned to 16, and the `Delegate::lock` may not be loaded into only one Cache Line (64B), which makes access to the lock slower. This can lead to performance degradation when concurrency is high. See https://bugs.mysql.com/bug.php?id=114361 for details. Implementation ============== Declare Delegate::lock to be aligned to 64. diff --git a/sql/rpl_handler.h b/sql/rpl_handler.h index d06f4c8071b..d34e042d471 100644 --- a/sql/rpl_handler.h +++ b/sql/rpl_handler.h @@ -211,9 +211,11 @@ class Delegate { /** List of registered observers */ Observer_info_list observer_info_list; /** - A read/write lock to be used when not optimizing for static plugin config + A read/write lock to be used when not optimizing for static plugin config. + Align lock to CPU_LEVEL1_DCACHE_LINESIZE to ensure it can be loaded into + one Cache Line, reduce performance loss in high concurrency scenarios. */ - mysql_rwlock_t lock; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_rwlock_t lock; /** A shared-exclusive spin lock to be used when optimizing for static plugin config.