mariadb/storage
Marko Mäkelä a2ee2c7ea1 MDEV-29930 Lock order inversion in ibuf_remove_free_page()
The function ibuf_remove_free_page() was waiting for ibuf_mutex
while holding ibuf.index->lock. This constitutes a lock order
inversion and may cause InnoDB to hang when innodb_change_buffering
is enabled and ibuf_merge_or_delete_for_page() is being executed
concurrently.

In fact, there is no need for ibuf_remove_free_page() to reacquire
ibuf_mutex if we make ibuf.seg_size and ibuf.free_list_len
protected by the ibuf.index->lock as well as the root page latch rather
than by ibuf_mutex.

ibuf.seg_size, ibuf.free_list_len: Instead of ibuf_mutex, let the
ibuf.index->lock and the root page latch protect these, like ibuf.empty.

ibuf_init_at_db_start(): Acquire the root page latch before updating
ibuf.seg_size. (The ibuf.index would be created later.)

ibuf_data_enough_free_for_insert(), ibuf_data_too_much_free():
Assert also ibuf.index->lock.have_u_or_x().

ibuf_remove_free_page(): Acquire the ibuf.index->lock and the root page
latch before accessing ibuf.free_list_len. Simplify the way how the
root page latch is released and reacquired. Acquire and release
ibuf_mutex only once.

ibuf_free_excess_pages(), ibuf_insert_low(): Acquire also ibuf.index->lock
before reading ibuf.free_list_len.

ibuf_print(): Acquire ibuf.index->lock before reading
ibuf.free_list_len and ibuf.seg_size.

Reviewed by: Vladislav Lesin
Tested by: Matthias Leich
2025-09-11 13:25:08 +03:00
..
archive Merge 10.6 into 10.11 2024-06-27 10:26:09 +03:00
blackhole MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
columnstore Merge branch '10.6' into 10.11 2025-07-28 18:06:31 +02:00
connect connect engine: correct two uninitalized variable errors 2025-07-29 13:15:02 +10:00
csv Merge 10.6 into 10.11 2025-08-22 06:47:54 +03:00
example MDEV-36729: ha_example::show_func_example is incorrectly defined 2025-05-29 10:10:52 +10:00
federated Merge 10.5 into 10.6 2024-11-29 12:37:46 +02:00
federatedx Merge branch '10.6' into '10.11' 2025-04-16 03:34:40 +02:00
heap Merge 10.5 into 10.6 2025-01-20 09:57:37 +02:00
innobase MDEV-29930 Lock order inversion in ibuf_remove_free_page() 2025-09-11 13:25:08 +03:00
maria Fix GCC -Wmaybe-uninitialized 2025-09-08 08:23:24 +03:00
mroonga MDEV-37502: mroonga+clang+debug violates its own setting of compile flags sign-compare 2025-09-11 10:02:43 +10:00
myisam Fixed typos 2025-09-04 18:08:39 +03:00
myisammrg Merge 10.6 into 10.11 2025-01-08 12:51:26 +02:00
oqgraph Merge 10.6 into 10.11 2024-11-29 13:43:17 +02:00
perfschema Merge 10.6 into 10.11 2025-08-22 06:47:54 +03:00
rocksdb MDEV-37502: clang/debug/rocksdb - stack frame size 2025-09-11 10:02:43 +10:00
sequence MDEV-33746 Supply missing override markings 2024-06-20 11:32:13 -04:00
sphinx Merge 10.5 into 10.6 2024-11-29 12:37:46 +02:00
spider MDEV-37204 fix view-protocol in spider/bugfix.index 2025-09-05 14:44:04 +10:00
test_sql_discovery Merge 10.5 into 10.6 2024-06-24 13:09:47 +03:00