Skip to content
/ server Public

Commit 4c94cd5

Browse files
committed
MDEV-38069 Heavy contention on buf_pool.flush_list_mutex
buf_do_flush_list_batch(): Release and reacquire buf_pool.flush_list_mutex after every 32 iterations, similar to how buf_flush_LRU_list_batch() releases buf_pool.mutex ever since commit 27ff972 (MDEV-26827 fixup). This regression was introduced in commit 22b62ed (MDEV-25113) and made more prominent by the recent commit a7f0d79 (MDEV-35155). Reviewed by: Thirunarayanan Balathandayuthapani Tested by: Saahil Alam Tested by: Rahul Raj
1 parent f0c2753 commit 4c94cd5

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed

storage/innobase/buf/buf0flu.cc

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,16 @@ static ulint buf_do_flush_list_batch(ulint max_n, lsn_t lsn) noexcept
14631463
buf_pool.delete_from_flush_list(bpage);
14641464
skip:
14651465
bpage= prev;
1466-
continue;
1466+
if (scanned & 31)
1467+
continue;
1468+
/* Release the buf_pool.flush_list_mutex every now and then
1469+
in order to reduce the wait time in buf_flush_ahead().
1470+
We attempt to preserve the pointer position while yielding.
1471+
Any thread that would remove 'prev' from buf_pool.flush_list
1472+
must adjust the hazard pointer. */
1473+
buf_pool.flush_hp.set(prev);
1474+
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
1475+
goto next;
14671476
}
14681477

14691478
ut_ad(oldest_modification > 2);
@@ -1491,51 +1500,54 @@ static ulint buf_do_flush_list_batch(ulint max_n, lsn_t lsn) noexcept
14911500
buf_pool.flush_hp.set(prev);
14921501
}
14931502

1494-
const page_id_t page_id(bpage->id());
1495-
const uint32_t space_id= page_id.space();
1496-
if (!space || space->id != space_id)
14971503
{
1498-
if (last_space_id != space_id)
1504+
const page_id_t page_id(bpage->id());
1505+
const uint32_t space_id= page_id.space();
1506+
if (!space || space->id != space_id)
14991507
{
1500-
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
1501-
mysql_mutex_unlock(&buf_pool.mutex);
1502-
if (space)
1503-
space->release();
1504-
auto p= buf_flush_space(space_id);
1505-
space= p.first;
1506-
last_space_id= space_id;
1507-
mysql_mutex_lock(&buf_pool.mutex);
1508-
buf_pool.stat.n_pages_written+= p.second;
1509-
mysql_mutex_lock(&buf_pool.flush_list_mutex);
1508+
if (last_space_id != space_id)
1509+
{
1510+
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
1511+
mysql_mutex_unlock(&buf_pool.mutex);
1512+
if (space)
1513+
space->release();
1514+
auto p= buf_flush_space(space_id);
1515+
space= p.first;
1516+
last_space_id= space_id;
1517+
mysql_mutex_lock(&buf_pool.mutex);
1518+
buf_pool.stat.n_pages_written+= p.second;
1519+
mysql_mutex_lock(&buf_pool.flush_list_mutex);
1520+
}
1521+
else
1522+
ut_ad(!space);
1523+
}
1524+
else if (space->is_stopping_writes())
1525+
{
1526+
space->release();
1527+
space= nullptr;
15101528
}
1511-
else
1512-
ut_ad(!space);
1513-
}
1514-
else if (space->is_stopping_writes())
1515-
{
1516-
space->release();
1517-
space= nullptr;
1518-
}
15191529

1520-
if (!space)
1521-
buf_flush_discard_page(bpage);
1522-
else
1523-
{
1524-
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
1525-
do
1530+
if (!space)
1531+
buf_flush_discard_page(bpage);
1532+
else
15261533
{
1527-
if (neighbors && space->is_rotational())
1528-
count+= buf_flush_try_neighbors(space, page_id, bpage,
1529-
neighbors == 1, count, max_n);
1530-
else if (bpage->flush(space))
1531-
++count;
1532-
else
1533-
continue;
1534-
mysql_mutex_lock(&buf_pool.mutex);
1534+
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
1535+
do
1536+
{
1537+
if (neighbors && space->is_rotational())
1538+
count+= buf_flush_try_neighbors(space, page_id, bpage,
1539+
neighbors == 1, count, max_n);
1540+
else if (bpage->flush(space))
1541+
++count;
1542+
else
1543+
continue;
1544+
mysql_mutex_lock(&buf_pool.mutex);
1545+
}
1546+
while (0);
15351547
}
1536-
while (0);
15371548
}
15381549

1550+
next:
15391551
mysql_mutex_lock(&buf_pool.flush_list_mutex);
15401552
bpage= buf_pool.flush_hp.get();
15411553
}

0 commit comments

Comments
 (0)