Why use swap when there is more than enough RAM.

Swappiness is a property of the Linux kernel that changes the balance between swapping out runtime memory, as opposed to dropping pages from the system page cache. Swappiness can be set to values between 0 and 100 inclusive. A low value means the kernel will try to avoid swapping as much as possible where a higher value instead will make the kernel aggressively try to use swap space. The default value is 60, and for most desktop systems, setting it to 100 may affect the overall performance, whereas setting it lower (even 0) may improve interactivity (by decreasing response latency.)

In short:

ValueStrategy
vm.swappiness = 0 The kernel will swap only to avoid an out of memory condition.
vm.swappiness = 60 The default value.
vm.swappiness = 100 The kernel will swap aggressively which may affect over all performance.


To temporarily set the swappiness in Linux, write the desired value (e.g. 10) to /proc/sys/vm/swappiness using the following command, running as root user:

# Set the swappiness value as root
echo 10 > /proc/sys/vm/swappiness 
 
# Alternatively, run this as a non-root user
sudo sysctl -w vm.swappiness=10
 
# Verify the change
cat /proc/sys/vm/swappiness
10

Permanent changes are made in /etc/sysctl.conf via the following configuration line (inserted if not present previously):

vm.swappiness = 10



释放swap
先free 看一下 可用内存是否能装的下swap已用的大小
确定可以后执行swapoff -a && swapon -a 然后free 检查下
posted @ 2013-10-18 10:49  sunsweet  阅读(331)  评论(0编辑  收藏  举报