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.
44Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
55
66This program is free software; you can redistribute it and/or modify it under
@@ -357,6 +357,7 @@ buf_flush_insert_into_flush_list(
357357buf_block_t * block,/* !< in/out: block which is modified */
358358lsn_t lsn)/* !< in: oldest modification */
359359{
360+ ut_ad (srv_shutdown_state != SRV_SHUTDOWN_FLUSH_PHASE);
360361ut_ad (log_flush_order_mutex_own ());
361362ut_ad (mutex_own (&block->mutex ));
362363
@@ -415,6 +416,7 @@ buf_flush_insert_sorted_into_flush_list(
415416buf_page_t * prev_b;
416417buf_page_t * b;
417418
419+ ut_ad (srv_shutdown_state != SRV_SHUTDOWN_FLUSH_PHASE);
418420ut_ad (log_flush_order_mutex_own ());
419421ut_ad (mutex_own (&block->mutex ));
420422ut_ad (buf_block_get_state (block) == BUF_BLOCK_FILE_PAGE);
@@ -720,6 +722,7 @@ buf_flush_write_complete(
720722buf_page_set_io_fix (bpage, BUF_IO_NONE);
721723
722724buf_pool->n_flush [flush_type]--;
725+ ut_ad (buf_pool->n_flush [flush_type] != ULINT_MAX);
723726
724727if (buf_pool->n_flush [flush_type] == 0
725728 && buf_pool->init_flush [flush_type] == FALSE ) {
@@ -1054,6 +1057,7 @@ buf_flush_page(
10541057}
10551058
10561059++buf_pool->n_flush [flush_type];
1060+ ut_ad (buf_pool->n_flush [flush_type] != 0 );
10571061
10581062mutex_exit (&buf_pool->flush_state_mutex );
10591063
@@ -2196,13 +2200,14 @@ Clears up tail of the LRU lists:
21962200* Flush dirty pages at the tail of LRU to the disk
21972201The depth to which we scan each buffer pool is controlled by dynamic
21982202config parameter innodb_LRU_scan_depth.
2199- @return number of pages flushed */
2203+ @return number of flushed and evicted pages */
22002204UNIV_INTERN
22012205ulint
22022206buf_flush_LRU_tail (void )
22032207/* ====================*/
22042208{
22052209ulint total_flushed = 0 ;
2210+ ulint total_evicted = 0 ;
22062211ulint start_time = ut_time_ms ();
22072212ulint scan_depth[MAX_BUFFER_POOLS];
22082213ulint requested_pages[MAX_BUFFER_POOLS];
@@ -2268,6 +2273,7 @@ buf_flush_LRU_tail(void)
22682273limited_scan[i]
22692274= (previous_evicted[i] > n.evicted );
22702275previous_evicted[i] = n.evicted ;
2276+ total_evicted += n.evicted ;
22712277
22722278requested_pages[i] += lru_chunk_size;
22732279
@@ -2300,7 +2306,7 @@ buf_flush_LRU_tail(void)
23002306MONITOR_LRU_BATCH_PAGES,
23012307total_flushed);
23022308}
2303- return (total_flushed);
2309+ return (total_flushed + total_evicted );
23042310}
23052311
23062312/* ********************************************************************/ /* *
@@ -2601,6 +2607,23 @@ buf_get_total_free_list_length(void)
26012607return result;
26022608}
26032609
2610+ /* * Returns the aggregate LRU list length over all buffer pool instances.
2611+ @return total LRU list length. */
2612+ MY_ATTRIBUTE ((warn_unused_result))
2613+ static
2614+ ulint
2615+ buf_get_total_LRU_list_length(void )
2616+ {
2617+ ulint result = 0 ;
2618+
2619+ for (ulint i = 0 ; i < srv_buf_pool_instances; i++) {
2620+
2621+ result += UT_LIST_GET_LEN (buf_pool_from_array (i)->LRU );
2622+ }
2623+
2624+ return result;
2625+ }
2626+
26042627/* ********************************************************************/ /* *
26052628Adjust the desired page cleaner thread sleep time for LRU flushes. */
26062629MY_ATTRIBUTE ((nonnull))
@@ -2613,8 +2636,9 @@ page_cleaner_adapt_lru_sleep_time(
26132636ulint lru_n_flushed) /* !< in: number of flushed in previous batch */
26142637
26152638{
2616- ulint free_len = buf_get_total_free_list_length ();
2617- ulint max_free_len = srv_LRU_scan_depth * srv_buf_pool_instances;
2639+ ulint free_len = buf_get_total_free_list_length ();
2640+ ulint max_free_len = ut_min (buf_get_total_LRU_list_length (),
2641+ srv_LRU_scan_depth * srv_buf_pool_instances);
26182642
26192643if (free_len < max_free_len / 100 && lru_n_flushed) {
26202644
@@ -2626,7 +2650,7 @@ page_cleaner_adapt_lru_sleep_time(
26262650
26272651/* Free lists filled more than 20%
26282652or no pages flushed in previous batch, sleep a bit more */
2629- *lru_sleep_time += 50 ;
2653+ *lru_sleep_time += 1 ;
26302654if (*lru_sleep_time > srv_cleaner_max_lru_time)
26312655*lru_sleep_time = srv_cleaner_max_lru_time;
26322656} else if (free_len < max_free_len / 20 && *lru_sleep_time >= 50 ) {
@@ -2673,6 +2697,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
26732697/* !< in: a dummy parameter required by
26742698os_thread_create */
26752699{
2700+ my_thread_init ();
26762701ulint next_loop_time = ut_time_ms () + 1000 ;
26772702ulint n_flushed = 0 ;
26782703ulint last_activity = srv_get_activity_count ();
@@ -2806,6 +2831,7 @@ DECLARE_THREAD(buf_flush_page_cleaner_thread)(
28062831thread_exit:
28072832buf_page_cleaner_is_active = FALSE ;
28082833
2834+ my_thread_end ();
28092835/* We count the number of threads in os_thread_exit(). A created
28102836thread should always use that to exit and not use return() to exit. */
28112837os_thread_exit (NULL );
0 commit comments