buf_flush_page_cleaner_thread
来源:互联网 发布:清朝留辫子原因 知乎 编辑:程序博客网 时间:2024/06/06 20:11
while (srv_shutdown_state == SRV_SHUTDOWN_NONE) { //1 server active或者有挂起的读IO请求或者n_flushed==0 // sleep 1微妙 if (srv_check_activity(last_activity) || buf_get_n_pending_read_ios() || n_flushed == 0) {page_cleaner_sleep_if_needed(next_loop_time); } //2 next_loop_time = ut_time_ms() + 1000; if (srv_check_activity(last_activity)) { last_activity = srv_get_activity_count(); //2.1 n_flushed = buf_flush_LRU_tail(); //2.2 n_flushed += page_cleaner_flush_pages_if_needed(); }else{ n_flushed = page_cleaner_do_flush_batch(PCT_IO(100),LSN_MAX); //刷srv_io_capacity个即200个page //page_cleaner_do_flush_batch->buf_flush_list->buf_flush_batch-> //buf_do_flush_list_batch: 刷flush_list脏页 }}
注:
PCT_IO(100) :200
#define PCT_IO(p) ((ulong) (srv_io_capacity * ((double) (p) / 100.0)))
大概是每秒调用一次:
2.1:buf_flush_LRU_tail
buf_flush_LRU//每次刷100个,扫描深度srv_LRU_scan_depth
buf_flush_batch->count = buf_do_LRU_batch(buf_pool, 100);->
buf_free_from_unzip_LRU_list_batch
buf_flush_LRU_list_batch
扫描深度是srv_LRU_scan_depth,每次检查100个block。优先检查unzip_LRU链表,然后LRU链表;如果有干净的页,则将其move到free链表。
问题:如果是热点页,岂不是就把热数据替换出去了?
2.2:page_cleaner_flush_pages_if_needed刷脏页,自动调整个数
主要涉及2个函数:
cur_lsn = log_get_lsn();oldest_lsn = buf_pool_get_oldest_modification();age = cur_lsn > oldest_lsn ? cur_lsn - oldest_lsn : 0;pct_for_dirty = af_get_pct_for_dirty();pct_for_lsn = af_get_pct_for_lsn(age);pct_total = ut_max(pct_for_dirty, pct_for_lsn);//avg_page_rate等于上一个srv_flushing_avg_loops循环里刷磁盘的脏页数的平均值//最大不会超过srv_max_io_capacity值n_pages = (PCT_IO(pct_total) + avg_page_rate) / 2;if (n_pages > srv_max_io_capacity) { n_pages = srv_max_io_capacity;}n_pages = page_cleaner_do_flush_batch(n_pages, oldest_lsn + lsn_avg_rate * (age_factor + 1));
阅读全文
0 0