Skip to content

Commit

Permalink
MDEV-26055: Correct the formula for adaptive flushing
Browse files Browse the repository at this point in the history
This is a 10.5 backport of 10.6
commit d4265fb.

page_cleaner_flush_pages_recommendation(): If dirty_pct is
between innodb_max_dirty_pages_pct_lwm
and innodb_max_dirty_pages_pct,
scale the effort relative to how close we are to
innodb_max_dirty_pages_pct.

The previous formula was missing a multiplication by 100.
  • Loading branch information
dr-m committed Nov 16, 2023
1 parent a3d0d5f commit 9a545eb
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions storage/innobase/buf/buf0flu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2120,10 +2120,12 @@ Based on various factors it decides if there is a need to do flushing.
@return number of pages recommended to be flushed
@param last_pages_in number of pages flushed in previous batch
@param oldest_lsn buf_pool.get_oldest_modification(0)
@param pct_lwm innodb_max_dirty_pages_pct_lwm, or 0 to ignore it
@param dirty_blocks UT_LIST_GET_LEN(buf_pool.flush_list)
@param dirty_pct 100*flush_list.count / (LRU.count + free.count) */
static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
lsn_t oldest_lsn,
double pct_lwm,
ulint dirty_blocks,
double dirty_pct)
{
Expand Down Expand Up @@ -2193,11 +2195,17 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
sum_pages = 0;
}

const ulint pct_for_dirty = srv_max_dirty_pages_pct_lwm == 0
? (dirty_pct >= max_pct ? 100 : 0)
: static_cast<ulint>
(max_pct > 0.0 ? dirty_pct / max_pct : dirty_pct);
ulint pct_total = std::max(pct_for_dirty, pct_for_lsn);
MONITOR_SET(MONITOR_FLUSH_PCT_FOR_LSN, pct_for_lsn);

double total_ratio;
if (pct_lwm == 0.0 || max_pct == 0.0) {
total_ratio = 1;
} else {
total_ratio = std::max(double(pct_for_lsn) / 100,
(dirty_pct / max_pct));
}

MONITOR_SET(MONITOR_FLUSH_PCT_FOR_DIRTY, ulint(total_ratio * 100));

/* Estimate pages to be flushed for the lsn progress */
lsn_t target_lsn = oldest_lsn
Expand All @@ -2223,7 +2231,7 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
pages_for_lsn = 1;
}

n_pages = (ulint(double(srv_io_capacity) * double(pct_total) / 100.0)
n_pages = (ulint(double(srv_io_capacity) * total_ratio)
+ avg_page_rate + pages_for_lsn) / 3;

if (n_pages > srv_max_io_capacity) {
Expand All @@ -2236,8 +2244,6 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,

MONITOR_SET(MONITOR_FLUSH_AVG_PAGE_RATE, avg_page_rate);
MONITOR_SET(MONITOR_FLUSH_LSN_AVG_RATE, lsn_avg_rate);
MONITOR_SET(MONITOR_FLUSH_PCT_FOR_DIRTY, pct_for_dirty);
MONITOR_SET(MONITOR_FLUSH_PCT_FOR_LSN, pct_for_lsn);

goto func_exit;
}
Expand Down Expand Up @@ -2349,31 +2355,40 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
const double dirty_pct= double(dirty_blocks) * 100.0 /
double(UT_LIST_GET_LEN(buf_pool.LRU) + UT_LIST_GET_LEN(buf_pool.free));

bool idle_flush= false;
double pct_lwm= 0.0;

if (lsn_limit || soft_lsn_limit);
else if (af_needed_for_redo(oldest_lsn));
else if (srv_max_dirty_pages_pct_lwm != 0.0)
if (srv_max_dirty_pages_pct_lwm != 0.0)
{
const double lwm= srv_max_dirty_pages_pct_lwm;
const ulint activity_count= srv_get_activity_count();
if (activity_count != last_activity_count)
{
last_activity_count= activity_count;
goto maybe_unemployed;
}
else if (buf_pool.page_cleaner_idle() && buf_pool.n_pend_reads == 0)
{
/* reaching here means 3 things:
- last_activity_count == activity_count: suggesting server is idle
(no trx_t::commit activity)
- page cleaner is idle (dirty_pct < srv_max_dirty_pages_pct_lwm)
- there are no pending reads but there are dirty pages to flush */
idle_flush= true;
buf_pool.update_last_activity_count(activity_count);
pct_lwm= lwm;
}
else
{
maybe_unemployed:
const bool below{dirty_pct < pct_lwm};
pct_lwm= 0.0;
if (below)
goto possibly_unemployed;
}

if (!idle_flush && dirty_pct < srv_max_dirty_pages_pct_lwm)
goto unemployed;
}
else if (dirty_pct < srv_max_buf_pool_modified_pct)
goto unemployed;
possibly_unemployed:
if (!lsn_limit && !soft_lsn_limit && !af_needed_for_redo(oldest_lsn))
goto set_idle;

if (UNIV_UNLIKELY(lsn_limit != 0) && oldest_lsn >= lsn_limit)
lsn_limit= buf_flush_sync_lsn= 0;
Expand All @@ -2393,7 +2408,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
n= srv_max_io_capacity;
goto background_flush;
}
else if (idle_flush || !srv_adaptive_flushing)
else if (pct_lwm != 0.0 || !srv_adaptive_flushing)
{
n= srv_io_capacity;
lsn_limit= LSN_MAX;
Expand All @@ -2409,6 +2424,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
}
else if ((n= page_cleaner_flush_pages_recommendation(last_pages,
oldest_lsn,
pct_lwm,
dirty_blocks,
dirty_pct)) != 0)
{
Expand All @@ -2431,7 +2447,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
mysql_mutex_unlock(&buf_pool.mutex);
last_pages+= n;

if (!idle_flush)
if (pct_lwm == 0.0)
goto end_of_batch;

/* when idle flushing kicks in page_cleaner is marked active.
Expand Down

0 comments on commit 9a545eb

Please sign in to comment.