buffe/cache占用过多导致Linux可用内存不足
使用free -h查看内存使用情况
[root@centos7 svn]# free -h
total used free shared buff/cache available
Mem: 15G 5.3G 251M 98M 9.9G 9.7G
Swap: 7.8G 2.6G 5.2G可以看出内存总量15G,剩余251M,其中buff/cache占用9.9G
Linux性能优化的两个重要参数
vfs_cache_pressure:
该数值表示内核回收用于directory和inode cache内存的倾向,这个值越大,越易回收;缺省值100表示内核将根据pagecache和swapcache,把directory和inode cache保持在一个合理的百分比;降低该值低于100,将导致内核倾向于保留directory和inode cache;增加该值超过100,将导致内核倾向于回收directory和inode cache。
缺省设置:100
min_free_kbytes:最小为 128K,最大为 64M
该数值代表系统所保留空闲内存的最低限(Kbytes)。min_free_kbytes设的越大,应用程序可使用的内存量越小,越容易导致OOM发生。min_free_kbytes设的过小,则会导致系统预留内存过小。
在系统初始化时会根据内存大小计算一个默认值,计算规则是:
min_free_kbytes = sqrt(lowmem_kbytes) 16 = 4 sqrt(lowmem_kbytes)
注:lowmem_kbytes即可认为是系统内存大小
16G内存默认min_free_kbytes = 4 * 4096 = 16384 Kbytes = 16M
改变命令:
sysctl -w vm.vfs_cache_pressure=200
sysctl -w vm.min_free_kbytes=16384查看:
[root@centos7 ~]# cat /proc/sys/vm/min_free_kbytes
16384
[root@centos7 ~]# cat /proc/sys/vm/vfs_cache_pressure
200