diff options
Diffstat (limited to 'storage/innobase/buf/buf0flu.cc')
-rw-r--r-- | storage/innobase/buf/buf0flu.cc | 91 |
1 files changed, 60 insertions, 31 deletions
diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index b702d79df8b..acfef5daad2 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -113,7 +113,12 @@ void buf_pool_t::page_cleaner_wakeup(bool for_LRU) { ut_d(buf_flush_validate_skip()); if (!page_cleaner_idle()) + { + if (for_LRU) + /* Ensure that the page cleaner is not in a timed wait. */ + pthread_cond_signal(&do_flush_list); return; + } double dirty_pct= double(UT_LIST_GET_LEN(buf_pool.flush_list)) * 100.0 / double(UT_LIST_GET_LEN(buf_pool.LRU) + UT_LIST_GET_LEN(buf_pool.free)); double pct_lwm= srv_max_dirty_pages_pct_lwm; @@ -209,7 +214,7 @@ void buf_flush_remove_pages(uint32_t id) if (!deferred) break; - os_aio_wait_until_no_pending_writes(); + os_aio_wait_until_no_pending_writes(true); } } @@ -1216,6 +1221,11 @@ static void buf_flush_LRU_list_batch(ulint max, bool evict, ++n->evicted; /* fall through */ case 1: + if (UNIV_LIKELY(scanned & 31)) + continue; + mysql_mutex_unlock(&buf_pool.mutex); + reacquire_mutex: + mysql_mutex_lock(&buf_pool.mutex); continue; } @@ -1251,32 +1261,37 @@ static void buf_flush_LRU_list_batch(ulint max, bool evict, auto p= buf_flush_space(space_id); space= p.first; last_space_id= space_id; + if (!space) + { + mysql_mutex_lock(&buf_pool.mutex); + goto no_space; + } mysql_mutex_lock(&buf_pool.mutex); - if (p.second) - buf_pool.stat.n_pages_written+= p.second; + buf_pool.stat.n_pages_written+= p.second; } else + { ut_ad(!space); + goto no_space; + } } else if (space->is_stopping()) { space->release(); space= nullptr; - } - - if (!space) - { + no_space: mysql_mutex_lock(&buf_pool.flush_list_mutex); buf_flush_discard_page(bpage); + continue; } - else if (neighbors && space->is_rotational()) + + if (neighbors && space->is_rotational()) { mysql_mutex_unlock(&buf_pool.mutex); n->flushed+= buf_flush_try_neighbors(space, page_id, bpage, neighbors == 1, do_evict, n->flushed, max); -reacquire_mutex: - mysql_mutex_lock(&buf_pool.mutex); + goto reacquire_mutex; } else if (n->flushed >= max && !recv_recovery_is_on()) { @@ -1643,7 +1658,7 @@ done: space->release(); if (space->purpose == FIL_TYPE_IMPORT) - os_aio_wait_until_no_pending_writes(); + os_aio_wait_until_no_pending_writes(true); else buf_dblwr.flush_buffered_writes(); @@ -1961,7 +1976,7 @@ static void buf_flush_wait(lsn_t lsn) break; } mysql_mutex_unlock(&buf_pool.flush_list_mutex); - os_aio_wait_until_no_pending_writes(); + os_aio_wait_until_no_pending_writes(false); mysql_mutex_lock(&buf_pool.flush_list_mutex); } } @@ -1996,16 +2011,20 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn) MONITOR_FLUSH_SYNC_COUNT, MONITOR_FLUSH_SYNC_PAGES, n_pages); } - os_aio_wait_until_no_pending_writes(); + os_aio_wait_until_no_pending_writes(false); mysql_mutex_lock(&buf_pool.flush_list_mutex); } while (buf_pool.get_oldest_modification(sync_lsn) < sync_lsn); } else #endif + { + thd_wait_begin(nullptr, THD_WAIT_DISKIO); + tpool::tpool_wait_begin(); buf_flush_wait(sync_lsn); - - thd_wait_end(nullptr); + tpool::tpool_wait_end(); + thd_wait_end(nullptr); + } } mysql_mutex_unlock(&buf_pool.flush_list_mutex); @@ -2164,10 +2183,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) { @@ -2237,11 +2258,17 @@ func_exit: 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 @@ -2267,7 +2294,7 @@ func_exit: 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) { @@ -2280,8 +2307,6 @@ func_exit: 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; } @@ -2394,7 +2419,7 @@ static void buf_flush_page_cleaner() soft_lsn_limit= lsn_limit; } - bool idle_flush= false; + double pct_lwm= 0.0; ulint n_flushed= 0, n; if (UNIV_UNLIKELY(soft_lsn_limit != 0)) @@ -2413,7 +2438,7 @@ static void buf_flush_page_cleaner() 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. @@ -2431,7 +2456,8 @@ static void buf_flush_page_cleaner() guaranteed to be nonempty, and it is a subset of buf_pool.LRU. */ const double dirty_pct= double(dirty_blocks) * 100.0 / double(UT_LIST_GET_LEN(buf_pool.LRU) + UT_LIST_GET_LEN(buf_pool.free)); - if (srv_max_dirty_pages_pct_lwm != 0.0) + pct_lwm= srv_max_dirty_pages_pct_lwm; + if (pct_lwm != 0.0) { const ulint activity_count= srv_get_activity_count(); if (activity_count != last_activity_count) @@ -2448,13 +2474,16 @@ static void buf_flush_page_cleaner() - there are no pending reads but there are dirty pages to flush */ buf_pool.update_last_activity_count(activity_count); mysql_mutex_unlock(&buf_pool.flush_list_mutex); - idle_flush= true; goto idle_flush; } else + { maybe_unemployed: - if (dirty_pct < srv_max_dirty_pages_pct_lwm) + const bool below{dirty_pct < pct_lwm}; + pct_lwm= 0.0; + if (below) goto possibly_unemployed; + } } else if (dirty_pct < srv_max_buf_pool_modified_pct) possibly_unemployed: @@ -2485,6 +2514,7 @@ static void buf_flush_page_cleaner() } else if ((n= page_cleaner_flush_pages_recommendation(last_pages, oldest_lsn, + pct_lwm, dirty_blocks, dirty_pct)) != 0) { @@ -2515,7 +2545,7 @@ static void buf_flush_page_cleaner() mysql_mutex_lock(&buf_pool.flush_list_mutex); buf_flush_wait_LRU_batch_end(); mysql_mutex_unlock(&buf_pool.flush_list_mutex); - os_aio_wait_until_no_pending_writes(); + os_aio_wait_until_no_pending_writes(false); } mysql_mutex_lock(&buf_pool.flush_list_mutex); @@ -2565,7 +2595,7 @@ ATTRIBUTE_COLD void buf_flush_buffer_pool() { mysql_mutex_unlock(&buf_pool.flush_list_mutex); buf_flush_list(srv_max_io_capacity); - os_aio_wait_until_no_pending_writes(); + os_aio_wait_until_no_pending_writes(false); mysql_mutex_lock(&buf_pool.flush_list_mutex); service_manager_extend_timeout(INNODB_EXTEND_TIMEOUT_INTERVAL, "Waiting to flush " ULINTPF " pages", @@ -2573,7 +2603,6 @@ ATTRIBUTE_COLD void buf_flush_buffer_pool() } mysql_mutex_unlock(&buf_pool.flush_list_mutex); - ut_ad(!os_aio_pending_writes()); ut_ad(!os_aio_pending_reads()); } |