Commit 9a545eb6 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-26055: Correct the formula for adaptive flushing

This is a 10.5 backport of 10.6
commit d4265fbd.

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.
parent a3d0d5fc
...@@ -2120,10 +2120,12 @@ Based on various factors it decides if there is a need to do flushing. ...@@ -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 @return number of pages recommended to be flushed
@param last_pages_in number of pages flushed in previous batch @param last_pages_in number of pages flushed in previous batch
@param oldest_lsn buf_pool.get_oldest_modification(0) @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_blocks UT_LIST_GET_LEN(buf_pool.flush_list)
@param dirty_pct 100*flush_list.count / (LRU.count + free.count) */ @param dirty_pct 100*flush_list.count / (LRU.count + free.count) */
static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in, static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
lsn_t oldest_lsn, lsn_t oldest_lsn,
double pct_lwm,
ulint dirty_blocks, ulint dirty_blocks,
double dirty_pct) double dirty_pct)
{ {
...@@ -2193,11 +2195,17 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in, ...@@ -2193,11 +2195,17 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
sum_pages = 0; sum_pages = 0;
} }
const ulint pct_for_dirty = srv_max_dirty_pages_pct_lwm == 0 MONITOR_SET(MONITOR_FLUSH_PCT_FOR_LSN, pct_for_lsn);
? (dirty_pct >= max_pct ? 100 : 0)
: static_cast<ulint> double total_ratio;
(max_pct > 0.0 ? dirty_pct / max_pct : dirty_pct); if (pct_lwm == 0.0 || max_pct == 0.0) {
ulint pct_total = std::max(pct_for_dirty, pct_for_lsn); 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 */ /* Estimate pages to be flushed for the lsn progress */
lsn_t target_lsn = oldest_lsn lsn_t target_lsn = oldest_lsn
...@@ -2223,7 +2231,7 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in, ...@@ -2223,7 +2231,7 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
pages_for_lsn = 1; 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; + avg_page_rate + pages_for_lsn) / 3;
if (n_pages > srv_max_io_capacity) { if (n_pages > srv_max_io_capacity) {
...@@ -2236,8 +2244,6 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in, ...@@ -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_AVG_PAGE_RATE, avg_page_rate);
MONITOR_SET(MONITOR_FLUSH_LSN_AVG_RATE, lsn_avg_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; goto func_exit;
} }
...@@ -2349,15 +2355,17 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*) ...@@ -2349,15 +2355,17 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
const double dirty_pct= double(dirty_blocks) * 100.0 / const double dirty_pct= double(dirty_blocks) * 100.0 /
double(UT_LIST_GET_LEN(buf_pool.LRU) + UT_LIST_GET_LEN(buf_pool.free)); 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); if (srv_max_dirty_pages_pct_lwm != 0.0)
else if (af_needed_for_redo(oldest_lsn));
else 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(); const ulint activity_count= srv_get_activity_count();
if (activity_count != last_activity_count) if (activity_count != last_activity_count)
{
last_activity_count= activity_count; last_activity_count= activity_count;
goto maybe_unemployed;
}
else if (buf_pool.page_cleaner_idle() && buf_pool.n_pend_reads == 0) else if (buf_pool.page_cleaner_idle() && buf_pool.n_pend_reads == 0)
{ {
/* reaching here means 3 things: /* reaching here means 3 things:
...@@ -2365,15 +2373,22 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*) ...@@ -2365,15 +2373,22 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
(no trx_t::commit activity) (no trx_t::commit activity)
- page cleaner is idle (dirty_pct < srv_max_dirty_pages_pct_lwm) - page cleaner is idle (dirty_pct < srv_max_dirty_pages_pct_lwm)
- there are no pending reads but there are dirty pages to flush */ - there are no pending reads but there are dirty pages to flush */
idle_flush= true;
buf_pool.update_last_activity_count(activity_count); 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) 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) if (UNIV_UNLIKELY(lsn_limit != 0) && oldest_lsn >= lsn_limit)
lsn_limit= buf_flush_sync_lsn= 0; lsn_limit= buf_flush_sync_lsn= 0;
...@@ -2393,7 +2408,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*) ...@@ -2393,7 +2408,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
n= srv_max_io_capacity; n= srv_max_io_capacity;
goto background_flush; goto background_flush;
} }
else if (idle_flush || !srv_adaptive_flushing) else if (pct_lwm != 0.0 || !srv_adaptive_flushing)
{ {
n= srv_io_capacity; n= srv_io_capacity;
lsn_limit= LSN_MAX; lsn_limit= LSN_MAX;
...@@ -2409,6 +2424,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*) ...@@ -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, else if ((n= page_cleaner_flush_pages_recommendation(last_pages,
oldest_lsn, oldest_lsn,
pct_lwm,
dirty_blocks, dirty_blocks,
dirty_pct)) != 0) dirty_pct)) != 0)
{ {
...@@ -2431,7 +2447,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*) ...@@ -2431,7 +2447,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
mysql_mutex_unlock(&buf_pool.mutex); mysql_mutex_unlock(&buf_pool.mutex);
last_pages+= n; last_pages+= n;
if (!idle_flush) if (pct_lwm == 0.0)
goto end_of_batch; goto end_of_batch;
/* when idle flushing kicks in page_cleaner is marked active. /* when idle flushing kicks in page_cleaner is marked active.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment