MySQL错误日志给出警告信息:
[Warning] InnoDB: Difficult to find free blocks in the buffer pool (336 search iterations)! 0 failed attempts to flush a page! Consider increasing the buffer pool size. It is also possible that in your Unix version fsync is very slow, or completely frozen inside the OS kernel. Then upgrading to a newer version of your operating system may help. Look at the number of fsyncs in diagnostic info below. Pending flushes (fsync) log: 0; buffer pool: 0. 1621989850 OS file reads, 1914021664 OS file writes, 110701569 OS fsyncs. Starting InnoDB Monitor to print further diagnostics to the standard output. 2019-10-26T15:02:03.962059Z 4520929 [Warning] InnoDB: Difficult to find free blocks in the buffer pool (337 search iterations)! 0 failed attempts to flush a page! Consider increasing the buffer pool size. It is also possible that in your Unix version fsync is very slow, or completely frozen inside the OS kernel. Then upgrading to a newer version of your operating system may help. Look at the number of fsyncs in diagnostic info below. Pending flushes (fsync) log: 0; buffer pool: 0. 1621989850 OS file reads, 1914021664 OS file writes, 110701569 OS fsyncs. Starting InnoDB Monitor to print further diagnostics to the standard output.
当InnoDB中的线程不断地请求空闲块,但无法从buffer pool中获得空闲块的时候,就会出现上面的警告消息。实际中,并不是这么简单,可能还有其他事情发生,懂得如何构建buffer pool中的块,就可以轻松的明白。
buffer pool主要由三个列表组成:
2.lru list:最近最少使用列表
·从free list中寻找一个空闲的块,如果有可用就分配它。如果不是,继续。
·扫描lru列表,如果找到干净(clean)的块,就将块移动到free list中,并分配。如果没有,继续。
·从lru列表的尾部刷新脏页,将其移动到free list,并分配。
这里是简化的步骤,只是为了便于理解,实际并不是这么简单,但类似。在任何时刻,如果块被移动到free list,就可以被任何线程使用,就可能使得当前的线程无法获取到块。当前线程就会每间隔10ms执行一次请求。
那什么时候会将警告信息写入日志呢?
当一个线程执行超过20迭代,就会将警告信息写入日志。下面是对应的源码块:
if (n_iterations > 20 & & srv_buf_pool_old_size == srv_buf_pool_size) {< strong > <= == == == Here it is < / strong > ib:: warn(ER_IB_MSG_134) << "Difficult to find free blocks in the buffer pool" " (" << n_iterations << " search iterations)! " << flush_failures << " failed attempts to" " flush a page! Consider increasing the buffer pool" " size. It is also possible that in your Unix version" " fsync is very slow, or completely frozen inside" " the OS kernel. Then upgrading to a newer version" " of your operating system may help. Look at the" " number of fsyncs in diagnostic info below." " Pending flushes (fsync) log: "
·IO子系统慢,不能满足需要及时将页刷新到磁盘
·page cleaner线程数量不够
1.增加buffer pool
2.调优、升级IO子系统
[Warning] InnoDB: Difficult to Find Free Blocks in the Buffer Pool