Locations of visitors to this page

Tuesday, May 5, 2009

swappiness 系统内核参数swappiness

swappiness
系统内核参数swappiness

swappiness是一个用来调整内存交换的内核参数, 这个值高意味着内核会有更多的交换, 较低的值意味着内核尽可能不用交换空间.
调整范围是0-100, 缺省值为60
# cat /proc/sys/vm/swappiness
60

# sysctl vm.swappiness
vm.swappiness = 60

可动态修改
# echo 0 >/proc/sys/vm/swappiness

# sysctl -w vm.swappiness=0
vm.swappiness = 0

持久化,使系统启动时生效
# sed -i '/^vm.swappiness/d;$a vm.swappiness=0' /etc/sysctl.conf


文章What Exactly is Swappiness?
对这个参数有所介绍

最后指出:
"For database servers I recommend to keep in mind the following criteria:

1. Use dedicated database servers and configure the most memory you can without exceeding the physical memory available. Running another memory-intensive application (e.g. an application server) on the same server as the database is a bad idea, as both will compete for memory, creating high swapping situations.
2. For database servers, set swappiness to 0. Use sysctl to set it interactively as quoted above, or better still, set it in the /etc/sysctl.conf file to persist when the server is restarted.
3. Constantly monitor the memory usage and swapping efficiency with a utility like sar."

后面有人答复, 如果MySQL使用InnoDB内存缓冲池,遇到交换页的问题, 应当升级内核到2.6.28版本
"you really should never have to touch this on 2.6, ever.

If you think you have any reason to, you are doing it wrong.

If you really do have problems with swapping, try 2.6.28 or later with split LRU.

http://feedblog.org/2009/01/25/splitlru-patch-in-kernel-2628-must-have-for-mysql-and-innodb/

http://www.surriel.com/node/26"



关于调整swappiness的大讨论:
Linux: Tuning Swappiness
Submitted by Jeremy on April 29, 2004 - 9:22am.



文章2.6 swapping behavior
[Posted May 5, 2004 by corbet]
介绍了算法:
So... swappiness, which is exported to /proc/sys/vm/swappiness, is a parameter which sets the kernel's balance between reclaiming pages from the page cache and swapping out process memory. The reclaim code works (in a very simplified way) by calculating a few numbers:

* The "distress" value is a measure of how much trouble the kernel is having freeing memory. The first time the kernel decides it needs to start reclaiming pages, distress will be zero; if more attempts are required, that value goes up, approaching a high value of 100.

* mapped_ratio is an approximate percentage of how much of the system's total memory is mapped (i.e. is part of a process's address space) within a given memory zone.

* vm_swappiness is the swappiness parameter, which is set to 60 by default.

With those numbers in hand, the kernel calculates its "swap tendency":

swap_tendency = mapped_ratio/2 + distress + vm_swappiness;

If swap_tendency is below 100, the kernel will only reclaim page cache pages. Once it goes above that value, however, pages which are part of some process's address space will also be considered for reclaim. So, if life is easy, swappiness is set to 60, and distress is zero, the system will not swap process memory until it reaches 80% of the total. Users who would like to never see application memory swapped out can set swappiness to zero; that setting will cause the kernel to ignore process memory until the distress value gets quite high.

可惜我没看懂





-fin-

No comments:

Website Analytics

Followers