Skip to content

Commit 22b62ed

Browse files
committed
MDEV-25113: Make page flushing faster
buf_page_write_complete(): Reduce the buf_pool.mutex hold time, and do not acquire buf_pool.flush_list_mutex at all. Instead, mark blocks clean by setting oldest_modification to 1. Dirty pages of temporary tables will be identified by the special value 2 instead of the previous special value 1. (By design of the ib_logfile0 format, actual LSN values smaller than 2048 are not possible.) buf_LRU_free_page(), buf_pool_t::get_oldest_modification() and many other functions will remove the garbage (clean blocks) from buf_pool.flush_list while holding buf_pool.flush_list_mutex. buf_pool_t::n_flush_LRU, buf_pool_t::n_flush_list: Replaced with non-atomic variables, protected by buf_pool.mutex, to avoid unnecessary synchronization when modifying the counts. export_vars: Remove unnecessary indirection for innodb_pages_created, innodb_pages_read, innodb_pages_written.
1 parent 8af5389 commit 22b62ed

File tree

13 files changed

+309
-245
lines changed

13 files changed

+309
-245
lines changed

storage/innobase/btr/btr0cur.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7101,7 +7101,7 @@ static void btr_blob_free(buf_block_t *block, bool all, mtr_t *mtr)
71017101
mysql_mutex_lock(&buf_pool.mutex);
71027102

71037103
if (buf_page_t *bpage= buf_pool.page_hash_get_low(page_id, fold))
7104-
if(!buf_LRU_free_page(bpage, all) && all && bpage->zip.data)
7104+
if (!buf_LRU_free_page(bpage, all) && all && bpage->zip.data)
71057105
/* Attempt to deallocate the redundant copy of the uncompressed page
71067106
if the whole ROW_FORMAT=COMPRESSED block cannot be deallocted. */
71077107
buf_LRU_free_page(bpage, false);

storage/innobase/buf/buf0buf.cc

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,13 +1346,15 @@ inline const buf_block_t *buf_pool_t::chunk_t::not_freed() const
13461346
break;
13471347
}
13481348

1349+
const lsn_t lsn= block->page.oldest_modification();
1350+
13491351
if (fsp_is_system_temporary(block->page.id().space()))
13501352
{
1351-
ut_ad(block->page.oldest_modification() <= 1);
1353+
ut_ad(lsn == 0 || lsn == 2);
13521354
break;
13531355
}
13541356

1355-
if (!block->page.ready_for_replace())
1357+
if (lsn > 1 || !block->page.can_relocate())
13561358
return block;
13571359

13581360
break;
@@ -1509,9 +1511,9 @@ void buf_pool_t::close()
15091511
Only on aborted startup (with recovery) or with innodb_fast_shutdown=2
15101512
we may discard changes. */
15111513
ut_d(const lsn_t oldest= bpage->oldest_modification();)
1512-
ut_ad(!oldest || srv_is_being_started ||
1513-
srv_fast_shutdown == 2 ||
1514-
(oldest == 1 && fsp_is_system_temporary(bpage->id().space())));
1514+
ut_ad(fsp_is_system_temporary(bpage->id().space())
1515+
? (oldest == 0 || oldest == 2)
1516+
: oldest <= 1 || srv_is_being_started || srv_fast_shutdown == 2);
15151517

15161518
if (bpage->state() != BUF_BLOCK_FILE_PAGE)
15171519
buf_page_free_descriptor(bpage);
@@ -3323,6 +3325,8 @@ buf_page_get_low(
33233325
mysql_mutex_unlock(&buf_pool.mutex);
33243326
buf_flush_list();
33253327
buf_flush_wait_batch_end_acquiring_mutex(false);
3328+
while (buf_flush_list_space(space));
3329+
os_aio_wait_until_no_pending_writes();
33263330

33273331
if (fix_block->page.buf_fix_count() == 1
33283332
&& !fix_block->page.oldest_modification()) {
@@ -4438,8 +4442,8 @@ void buf_pool_t::print()
44384442
<< UT_LIST_GET_LEN(flush_list)
44394443
<< ", n pending decompressions=" << n_pend_unzip
44404444
<< ", n pending reads=" << n_pend_reads
4441-
<< ", n pending flush LRU=" << n_flush_LRU
4442-
<< " list=" << n_flush_list
4445+
<< ", n pending flush LRU=" << n_flush_LRU_
4446+
<< " list=" << n_flush_list_
44434447
<< ", pages made young=" << stat.n_pages_made_young
44444448
<< ", not young=" << stat.n_pages_not_made_young
44454449
<< ", pages read=" << stat.n_pages_read
@@ -4538,7 +4542,6 @@ void buf_stats_get_pool_info(buf_pool_info_t *pool_info)
45384542
double time_elapsed;
45394543

45404544
mysql_mutex_lock(&buf_pool.mutex);
4541-
mysql_mutex_lock(&buf_pool.flush_list_mutex);
45424545

45434546
pool_info->pool_size = buf_pool.curr_size;
45444547

@@ -4548,17 +4551,17 @@ void buf_stats_get_pool_info(buf_pool_info_t *pool_info)
45484551

45494552
pool_info->free_list_len = UT_LIST_GET_LEN(buf_pool.free);
45504553

4554+
mysql_mutex_lock(&buf_pool.flush_list_mutex);
45514555
pool_info->flush_list_len = UT_LIST_GET_LEN(buf_pool.flush_list);
45524556

45534557
pool_info->n_pend_unzip = UT_LIST_GET_LEN(buf_pool.unzip_LRU);
4558+
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
45544559

45554560
pool_info->n_pend_reads = buf_pool.n_pend_reads;
45564561

4557-
pool_info->n_pending_flush_lru = buf_pool.n_flush_LRU;
4558-
4559-
pool_info->n_pending_flush_list = buf_pool.n_flush_list;
4562+
pool_info->n_pending_flush_lru = buf_pool.n_flush_LRU_;
45604563

4561-
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
4564+
pool_info->n_pending_flush_list = buf_pool.n_flush_list_;
45624565

45634566
current_time = time(NULL);
45644567
time_elapsed = 0.001 + difftime(current_time,

0 commit comments

Comments
 (0)