Skip to content

Commit

Permalink
MDEV-25113: Make page flushing faster
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Jun 23, 2021
1 parent 8af5389 commit 22b62ed
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 245 deletions.
2 changes: 1 addition & 1 deletion storage/innobase/btr/btr0cur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7101,7 +7101,7 @@ static void btr_blob_free(buf_block_t *block, bool all, mtr_t *mtr)
mysql_mutex_lock(&buf_pool.mutex);

if (buf_page_t *bpage= buf_pool.page_hash_get_low(page_id, fold))
if(!buf_LRU_free_page(bpage, all) && all && bpage->zip.data)
if (!buf_LRU_free_page(bpage, all) && all && bpage->zip.data)
/* Attempt to deallocate the redundant copy of the uncompressed page
if the whole ROW_FORMAT=COMPRESSED block cannot be deallocted. */
buf_LRU_free_page(bpage, false);
Expand Down
27 changes: 15 additions & 12 deletions storage/innobase/buf/buf0buf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1346,13 +1346,15 @@ inline const buf_block_t *buf_pool_t::chunk_t::not_freed() const
break;
}

const lsn_t lsn= block->page.oldest_modification();

if (fsp_is_system_temporary(block->page.id().space()))
{
ut_ad(block->page.oldest_modification() <= 1);
ut_ad(lsn == 0 || lsn == 2);
break;
}

if (!block->page.ready_for_replace())
if (lsn > 1 || !block->page.can_relocate())
return block;

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

if (bpage->state() != BUF_BLOCK_FILE_PAGE)
buf_page_free_descriptor(bpage);
Expand Down Expand Up @@ -3323,6 +3325,8 @@ buf_page_get_low(
mysql_mutex_unlock(&buf_pool.mutex);
buf_flush_list();
buf_flush_wait_batch_end_acquiring_mutex(false);
while (buf_flush_list_space(space));
os_aio_wait_until_no_pending_writes();

if (fix_block->page.buf_fix_count() == 1
&& !fix_block->page.oldest_modification()) {
Expand Down Expand Up @@ -4438,8 +4442,8 @@ void buf_pool_t::print()
<< UT_LIST_GET_LEN(flush_list)
<< ", n pending decompressions=" << n_pend_unzip
<< ", n pending reads=" << n_pend_reads
<< ", n pending flush LRU=" << n_flush_LRU
<< " list=" << n_flush_list
<< ", n pending flush LRU=" << n_flush_LRU_
<< " list=" << n_flush_list_
<< ", pages made young=" << stat.n_pages_made_young
<< ", not young=" << stat.n_pages_not_made_young
<< ", pages read=" << stat.n_pages_read
Expand Down Expand Up @@ -4538,7 +4542,6 @@ void buf_stats_get_pool_info(buf_pool_info_t *pool_info)
double time_elapsed;

mysql_mutex_lock(&buf_pool.mutex);
mysql_mutex_lock(&buf_pool.flush_list_mutex);

pool_info->pool_size = buf_pool.curr_size;

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

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

mysql_mutex_lock(&buf_pool.flush_list_mutex);
pool_info->flush_list_len = UT_LIST_GET_LEN(buf_pool.flush_list);

pool_info->n_pend_unzip = UT_LIST_GET_LEN(buf_pool.unzip_LRU);
mysql_mutex_unlock(&buf_pool.flush_list_mutex);

pool_info->n_pend_reads = buf_pool.n_pend_reads;

pool_info->n_pending_flush_lru = buf_pool.n_flush_LRU;

pool_info->n_pending_flush_list = buf_pool.n_flush_list;
pool_info->n_pending_flush_lru = buf_pool.n_flush_LRU_;

mysql_mutex_unlock(&buf_pool.flush_list_mutex);
pool_info->n_pending_flush_list = buf_pool.n_flush_list_;

current_time = time(NULL);
time_elapsed = 0.001 + difftime(current_time,
Expand Down
Loading

0 comments on commit 22b62ed

Please sign in to comment.