Rootop 服务器运维与web架构

配置linux尽可能使用物理内存

有台测试机zabbx最近一直报交换分区不足,查看内存cache用了近20G,想配置系统尽量使用物理内存。通过配置系统参数swappiness可以实现。

redhat性能调整参考:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-configuration_tools-configuring_system_memory_capacity

swappiness
The swappiness value, ranging from 0 to 100, controls the degree to which the system favors anonymous memory or the page cache. A high value improves file-system performance while aggressively swapping less active processes out of RAM. A low value avoids swapping processes out of memory, which usually decreases latency at the cost of I/O performance. The default value is 60.
简单意思就是swappiness值越小,则尽可能利用物理内存,值越大,则用交换分区。默认值60。
官方文档也没看到说默认值60是指已用还是剩余60%的内存。

官方有个警告提醒:
Setting swappiness==0 will very aggressively avoids swapping out, which increase the risk of OOM killing under strong memory and I/O pressure.
设置为0的话,则非常积极的使用物理内存,但容易出现OOM的风险。

个人理解设置为0,”关闭” 使用交换分区,设置为100,积极使用交换分区。

# 2种方法查看当前值

[root@hub ~]# cat /proc/sys/vm/swappiness
30

[root@hub ~]# sysctl -q vm.swappiness
vm.swappiness = 30

# 修改默认值:

[root@localhost ~]# vi /etc/sysctl.conf 追加一行
vm.swappiness = 10
保存退出,执行。
[root@localhost ~]# sysctl -p
[root@localhost ~]# sysctl -q vm.swappiness
vm.swappiness = 10

执行完交换分区使用率不会立即释放,可能会由系统自动调整。
建议重启下机器,或者在业务上线前进行配置。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4355.html

作者:Venus

服务器运维与性能优化

评论已关闭。