innodb_lru_scan_depth是5.6新增加的參數,根據 官方文檔 描述,它會影響page cleaner線程每次刷臟頁的數量,
這是一個每1秒 loop一次的線程。在Innodb內部,這個參數對應變量為srv_LRU_scan_depth,grep了一把,有幾個地方會涉及到這個參數
page cleaner 線程 刷臟頁的長度,從尾部開始刷 srv_LRU_scan_depth
LRU 連表由 NEW 與 OLD 區構成
1.buf/buf0lru.cc
buf_LRU_free_from_unzip_LRU_list
從unzip_LRU_list取得空閑塊
在掃描bp->unzip_LRU時保證掃描深度不超過srv_LRU_scan_depth,以從其中釋放一個壓縮塊的非壓縮頁。
在5.5中,則有一個計算公式
distance = 100 + (n_iterations
* UT_LIST_GET_LEN(buf_pool->unzip_LRU)) / 5;
n_iterations越大,表示掃描了多次(或者說一次請求空閑塊進入這個函數的次數),值不超過5.
buf_LRU_free_from_common_LRU_list
從通用LRU鏈上取空閑塊
與上述情況類似,但掃描的是bp->LRU。
這兩個函數主要用於從LRU獲取空閑塊(例如free list已空),均有一個參數scan_all,當為true時,表示掃描全部LRU鏈表,這時候srv_LRU_scan_depth就不起作用了。
我們知道獲取空閑塊的入口函數是buf_LRU_get_free_block,之前也做過5.5關於這個函數的分析(見 http://mysqllover.com/?p=387 )
buf_LRU_get_free_block 取空閑塊 函數
在5.6中,如果free list為空,則
>如果有flush在發生,等待完成並重試
>如果buf_pool->try_LRU_scan為true,則掃描srv_LRU_scan_depth深度的LRU,成功則返回空閑快
>如果上一步失敗,iteration=1,掃描整個LRU鏈表
>如果上一步失敗,iteration>1,依然掃描整個LRU鏈表,但sleep 100000us
2.buf/buf0flu.cc:
這里主要是page cleaner線程調用
page cleaner線程
buf_flush_page_cleaner_thread //page cleaner線程入口
|—>buf_flush_LRU_tail
|–>掃描LRU,調用srv_LRU_scan_depth/PAGE_CLEANER_LRU_BATCH_CHUNK_SIZE()
次buf_flush_LRU函數,每次嘗試去處理100個block.
划分成chunk的目的是防止用戶線程在請求空閑塊時等待時間太長
srv_LRU_scan_depth/PAGE_CLEANER_LRU_BATCH_CHUNK_SIZE()
buf_flush_LRU LRU刷新函數
buf_flush_LRU-> buf_do_LRU_batch
buf_free_from_unzip_LRU_list_batch
從buf_pool->unzip_LRU上把非壓縮frame移到bp->free上,如果bp->free的長度大於等於srv_LRU_scan_depth會跳出
buf_flush_LRU_list_batch
和上面的類似,但是從bp->LRU上掃描
可見srv_LRU_scan_depth會控制從LRU上清理block並將其放到free list上的掃描深度,不光影響page cleaner線程,也會影響用戶線程;
從其作用可以看出,當系統的IO比較空閑的時候,可以適當將這個參數設大,當IO吃緊時,需要適當減小
related bug:
http://bugs.mysql.com/bug.php?id=68481
http://bugs.mysql.com/bug.php?id=68497
related blog:
http://mysqlha.blogspot.com/2013/02/mysql-56-io-bound-update-only-workloads.html
/*******************************************************************//** Flush and move pages from LRU or unzip_LRU list to the free list. Whether LRU or unzip_LRU is used depends on the state of the system. @return number of blocks for which either the write request was queued or in case of unzip_LRU the number of blocks actually moved to the free list */
static ulint buf_do_LRU_batch( /*=============*/ buf_pool_t* buf_pool, /*!< in: buffer pool instance */ ulint max ) /*!< in: desired number of blocks in the free_list */ { ulint count = 0; if (buf_LRU_evict_from_unzip_LRU(buf_pool)) { count += buf_free_from_unzip_LRU_list_batch(buf_pool, max); } if (max > count) { count += buf_flush_LRU_list_batch(buf_pool, max - count); } return(count); }
