11/* ****************************************************************************
22
3- Copyright (c) 1995, 2016 , Oracle and/or its affiliates. All Rights Reserved.
3+ Copyright (c) 1995, 2017 , Oracle and/or its affiliates. All Rights Reserved.
44
55This program is free software; you can redistribute it and/or modify it under
66the terms of the GNU General Public License as published by the Free Software
@@ -356,6 +356,7 @@ buf_flush_insert_into_flush_list(
356356buf_block_t * block,/* !< in/out: block which is modified */
357357lsn_t lsn)/* !< in: oldest modification */
358358{
359+ ut_ad (srv_shutdown_state != SRV_SHUTDOWN_FLUSH_PHASE);
359360ut_ad (log_flush_order_mutex_own ());
360361ut_ad (mutex_own (&block->mutex ));
361362
@@ -414,6 +415,7 @@ buf_flush_insert_sorted_into_flush_list(
414415buf_page_t * prev_b;
415416buf_page_t * b;
416417
418+ ut_ad (srv_shutdown_state != SRV_SHUTDOWN_FLUSH_PHASE);
417419ut_ad (log_flush_order_mutex_own ());
418420ut_ad (mutex_own (&block->mutex ));
419421ut_ad (buf_block_get_state (block) == BUF_BLOCK_FILE_PAGE);
@@ -724,6 +726,7 @@ buf_flush_write_complete(
724726buf_page_set_io_fix (bpage, BUF_IO_NONE);
725727
726728buf_pool->n_flush [flush_type]--;
729+ ut_ad (buf_pool->n_flush [flush_type] != ULINT_MAX);
727730
728731/* fprintf(stderr, "n pending flush %lu\n",
729732buf_pool->n_flush[flush_type]); */
@@ -1061,6 +1064,7 @@ buf_flush_page(
10611064}
10621065
10631066++buf_pool->n_flush [flush_type];
1067+ ut_ad (buf_pool->n_flush [flush_type] != 0 );
10641068
10651069mutex_exit (&buf_pool->flush_state_mutex );
10661070
@@ -2206,13 +2210,14 @@ Clears up tail of the LRU lists:
22062210* Flush dirty pages at the tail of LRU to the disk
22072211The depth to which we scan each buffer pool is controlled by dynamic
22082212config parameter innodb_LRU_scan_depth.
2209- @return number of pages flushed */
2213+ @return number of flushed and evicted pages */
22102214UNIV_INTERN
22112215ulint
22122216buf_flush_LRU_tail (void )
22132217/* ====================*/
22142218{
22152219ulint total_flushed = 0 ;
2220+ ulint total_evicted = 0 ;
22162221ulint start_time = ut_time_ms ();
22172222ulint scan_depth[MAX_BUFFER_POOLS];
22182223ulint requested_pages[MAX_BUFFER_POOLS];
@@ -2278,6 +2283,7 @@ buf_flush_LRU_tail(void)
22782283limited_scan[i]
22792284= (previous_evicted[i] > n.evicted );
22802285previous_evicted[i] = n.evicted ;
2286+ total_evicted += n.evicted ;
22812287
22822288requested_pages[i] += lru_chunk_size;
22832289
@@ -2310,7 +2316,7 @@ buf_flush_LRU_tail(void)
23102316MONITOR_LRU_BATCH_PAGES,
23112317total_flushed);
23122318}
2313- return (total_flushed);
2319+ return (total_flushed + total_evicted );
23142320}
23152321
23162322/* ********************************************************************/ /* *
@@ -2604,6 +2610,23 @@ buf_get_total_free_list_length(void)
26042610return result;
26052611}
26062612
2613+ /* * Returns the aggregate LRU list length over all buffer pool instances.
2614+ @return total LRU list length. */
2615+ MY_ATTRIBUTE ((warn_unused_result))
2616+ static
2617+ ulint
2618+ buf_get_total_LRU_list_length(void )
2619+ {
2620+ ulint result = 0 ;
2621+
2622+ for (ulint i = 0 ; i < srv_buf_pool_instances; i++) {
2623+
2624+ result += UT_LIST_GET_LEN (buf_pool_from_array (i)->LRU );
2625+ }
2626+
2627+ return result;
2628+ }
2629+
26072630/* ********************************************************************/ /* *
26082631Adjust the desired page cleaner thread sleep time for LRU flushes. */
26092632MY_ATTRIBUTE ((nonnull))
@@ -2616,8 +2639,9 @@ page_cleaner_adapt_lru_sleep_time(
26162639ulint lru_n_flushed) /* !< in: number of flushed in previous batch */
26172640
26182641{
2619- ulint free_len = buf_get_total_free_list_length ();
2620- ulint max_free_len = srv_LRU_scan_depth * srv_buf_pool_instances;
2642+ ulint free_len = buf_get_total_free_list_length ();
2643+ ulint max_free_len = ut_min (buf_get_total_LRU_list_length (),
2644+ srv_LRU_scan_depth * srv_buf_pool_instances);
26212645
26222646if (free_len < max_free_len / 100 && lru_n_flushed) {
26232647
@@ -2629,7 +2653,7 @@ page_cleaner_adapt_lru_sleep_time(
26292653
26302654/* Free lists filled more than 20%
26312655or no pages flushed in previous batch, sleep a bit more */
2632- *lru_sleep_time += 50 ;
2656+ *lru_sleep_time += 1 ;
26332657if (*lru_sleep_time > srv_cleaner_max_lru_time)
26342658*lru_sleep_time = srv_cleaner_max_lru_time;
26352659} else if (free_len < max_free_len / 20 && *lru_sleep_time >= 50 ) {
@@ -2676,6 +2700,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
26762700/* !< in: a dummy parameter required by
26772701os_thread_create */
26782702{
2703+ my_thread_init ();
26792704ulint next_loop_time = ut_time_ms () + 1000 ;
26802705ulint n_flushed = 0 ;
26812706ulint last_activity = srv_get_activity_count ();
@@ -2812,6 +2837,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
28122837thread_exit:
28132838buf_page_cleaner_is_active = FALSE ;
28142839
2840+ my_thread_end ();
28152841/* We count the number of threads in os_thread_exit(). A created
28162842thread should always use that to exit and not use return() to exit. */
28172843os_thread_exit (NULL );
0 commit comments