1. /proc/sys/vm/swappiness

vm.swappiness,定义内核交换内存页面的积极程度。较高的值会增加攻击性,较低的值会减少交换量。建议将值设置为10来避免交换延迟。

是控制系统对交换空间的使用程度,0表示尽量不使用swap交换空间,100表示积极的使用swap空间,默认值是60。

由于使用swap交换空间会产生磁盘IO,一定程度上影响了系统的性能,因此根据实际情况修改swappiness值能有效改善系统性能。

如果对系统的性能产生怀疑,一般建议将swappiness的值改为10

临时改:
echo 10 >/proc/sys/vm/swappiness

永久修改:
echo "vm.swappiness=10" >> /etc/sysctl.conf
sysctl -p

对于特殊的业务,比如MySQL总希望最大使用RAM内存而不是swap,这时将swappiness设置成1将是最合适的。

在kernel version 3.5以后和Redhat 2.6.32-303以后swappiness的0和1值意义是不一样。设置成1表示尽可能的使用内存,0表示尽可能不使用swap;在设置成0时,内存不足时很有可能会产生OOM,如果是MySQL服务器,kill掉可能就是MySQL进程。

设置 /proc/(pidof -s mysqld)/oom_adj为较小的值来尽量避免MySQL由于内存不足而被关闭

swappiness This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase agressiveness, lower values decrease the amount of swap.

The default value is 60.

Value Strategy
vm.swappiness = 0 The kernel will swap only to avoid an [out of memory](https://en.wikipedia.org/wiki/Out_of_memory "Out of memory") condition, when free memory will be below `vm.min_free_kbytes` limit. See the <cite class="citation web" style="font-style: inherit; word-wrap: break-word;">["VM Sysctl documentation"](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/sysctl/vm.txt).</cite>
vm.swappiness = 1 Kernel version 3.5 and over, as well as Red Hat kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
vm.swappiness = 10 This value is sometimes recommended to improve performance when sufficient memory exists in a system.
vm.swappiness = 60 The default value.
vm.swappiness = 100 The kernel will swap aggressively.

With kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over, it is likely better to use 1 for cases where 0 used to be optimal.[2]</sup>

https://en.wikipedia.org/wiki/Swappiness http://blog.csdn.net/longxibendi/article/details/38146521 https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/sysctl/vm.txt http://gitorious.ti.com/ti-linux-kernel/ti-linux-kernel/commit/fe35004fbf9eaf67482b074a2e032abb9c89b1dd?format=patch

Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2023-06-19 08:59:50

results matching ""

    No results matching ""