关于vm.min_free_kbytes的合理设置推测
关于vm.min_free_kbytes的合理设置推测
zphj1987前言
之前系统出现过几次hung住的情况,没有oom,也没有其它内存相关的信息,而linux设计就是去尽量吃满内存,然后再回收清理的机制
探讨
目前这个参数还没有找到合适的处理这个预留的参数,一般也没有去调整的
系统是默认根据物理内存进行计算得到一个数值得
1 | sysctl -a|grep min_free_kbytes |
查看内核参数,这个小环境是保留的45M
网上的一些说法
Aerospike 的说法
https://discuss.aerospike.com/t/how-to-tune-the-linux-kernel-for-memory-performance/4195
The standard RedHat recommendation 204 is to keep min_free_kbytes at 1-3% of the total memory on the system, with Aerospike advising to keep at least 1.1GB, even if that is above the official recommended total memory percentage.
On a system with over 37GB of total RAM, you should leave no more than 3% of spare memory to min_free_kbytes in order to avoid the kernel spending too much time unnecessarily reclaiming memory. This would equal anywhere between 1.1GB and 3% of total RAM on such systems.
上面的说法是如果环境内存超过37G的情况下,按3%算就是1.1G,我们一般的环境也超过了40G,那么基本就是建议最少留个1.1G的,100G的可以保留到3G左右
内核参数
vm.min_free_kbytes = 1153434
vm.min_free_kbytes = 3145728
红帽的说法
Setting min_free_kbytes too low prevents the system from reclaiming memory. This can result in system hangs and OOM-killing multiple processes.
However, setting min_free_kbytes too high (for example, to 5–10% of total system memory) causes the system to enter an out-of-memory state immediately, resulting in the system spending too much time reclaiming memory.
红帽的说法是需要低于总内存的5%
ltp测试里面的参数控制
https://sourceforge.net/p/ltp/mailman/message/29738250/
1 | Setting min_free_kbytes too high will cause system hangs, |
1 | * Description: |
测试用例里面测试内存过载情况下的几种参数,默认,两倍默认,5%空闲内存,或者总内存的2%,理论上,这几个都不会导致机器hung死
其它知识
通过slabtop查看内核的缓存空间占用
1 | [root@VM_0_17_centos ~]# slabtop -o|grep Total |
1 | [root@VM_0_17_centos ~]# grep Slab /proc/meminfo |
1 | [root@VM_0_17_centos ~]# sysctl -a|grep min_free_kbytes |
这个上面是腾讯云主机的,看到内核自身的占用应该在100M以上了,而我自己的vmware里面的虚拟机这个数值是47MB,这个数值可能跟不同的内核有关
系统还保留了一定的内存防止
1 | Reserving 161MB of memory at 688MB for crashkernel (System RAM: 2047MB) |
系统启动的时候看到的内存占用
1 | [root@lab204 ~]# dmesg |grep Memory: |
内核文档关于这个参数的解释
https://www.kernel.org/doc/Documentation/sysctl/vm.txt
1 | min_free_kbytes: |
基于以上暂时推测
建议能保留1G以上的空间
变更记录
Why | Who | When |
---|---|---|
创建 | 武汉-运维-磨渣 | 2020-09-09 |