使用内存缓冲小尺寸读写来降低磁盘 IO

我自己的系统磁盘写的 IO 一直很高,都是以数据库居多,看完这篇文章,决定也测试一下:

两个内核参数:
vm.dirty_ratio – The highest % of your memory that can be used to hold dirty data. If you set this to a low value, the kernel will flush small writes to the disk more often. Higher values allow the small writes to stack up in memory. They’ll go to the disk in bigger chunks.

vm.dirty_background_ratio – The lowest % of your memory where pdflush is told to stop when it is writing dirty data. You’ll want to keep this set as low as possible.

先手工修改

echo 5 > /proc/sys/vm/dirty_background_ratio
echo 60 > /proc/sys/vm/dirty_ratio

如果可行的话,写入 /etc/sysctl.conf:

vm.dirty_background_ratio = 5
vm.dirty_ratio = 60

按照作者的说法:
If you have a reliable server with a good RAID card and power supply, you could set the dirty_ratio to 100 and the dirty_background_ratio to 1. This was recommended by a buddy of mine who runs quite a few servers running virtual machines.

我的系统上原来的参数是 7 和 29 ,我修改为 5 和 60 看看。

可惜我 Cacti 上没有打开磁盘 IO 的监测,等有时间了,做个对比。