[MDEV-24167] InnoDB unnecessarily uses complex rw-lock implementation Created: 2020-11-09 Updated: 2024-02-08 Resolved: 2020-11-24 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Affects Version/s: | 10.5 |
| Fix Version/s: | 10.6.0 |
| Type: | Bug | Priority: | Major |
| Reporter: | Marko Mäkelä | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Scalability, performance, performance_schema | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
InnoDB implements its own complex rw-latch whose special features (recursive X-locks and SX-locks) are only needed for buf_block_t::lock and dict_index_t::lock. It would be tempting to use the lightweight wrapper mysql_rwlock_t, but unfortunately it would introduce a performance regression on Linux. On Microsoft Windows, we can use a straightforward wrapper of SRWLOCK. On Linux, a std::atomic<uint32_t> and a futex will do. On anything else, we can use mysql_rwlock_t. |
| Comments |
| Comment by Marko Mäkelä [ 2020-11-09 ] |
|
On my Debian GNU/Linux system, sizeof(mysql_rwlock_t) is 64 bytes, while sizeof(rw_lock_t) is 160 bytes or 88 bytes, depending on whether a debug build is being used. |
| Comment by Marko Mäkelä [ 2020-11-16 ] |
|
For contended rw-locks, such as the adaptive hash index latches, the custom implementation is measurably faster than mysql_rwlock_t. Hence, it makes sense to improve the custom implementation, in |
| Comment by Marko Mäkelä [ 2020-11-19 ] |
|
For all InnoDB rw-locks except those that will be addressed in |
| Comment by Marko Mäkelä [ 2020-11-20 ] |
|
My std::atomic<uint32_t> based implementation was improved in |
| Comment by Marko Mäkelä [ 2020-12-15 ] |
|
To prepare for |
| Comment by Marko Mäkelä [ 2020-12-16 ] |
|
Especially on Microsoft Windows (probably due to the hardware configuration rather than the operating system), we observed hung ssux_lock::update_lock(), mainly during the test mariabackup.xb_compressed_encrypted. Making ssux_lock::u_unlock() always wake up all waiters seemed to help. I suspect that the issue simply was that if multiple concurrent update_lock() ended up waiting, not all of them would be woken up. For X-locks, this problem was prevented by having a separate ‘waiting’ flag. For U-locks, we do not have such a flag. For some reason, the issue was not observable before we replaced the InnoDB homebrew mutex implementation with system mutexes in |
| Comment by Marko Mäkelä [ 2020-12-16 ] |
|
An unrelated cause of mariabackup.xb_compression_encrypted test timeouts was that the innodb_encryption_threads=4 were fighting each other and causing contention. Before |