youyou2011
2016-05-24 03:12 deepin
释放Swap分区空间
使用swapoff关闭交换分区
[root@testlnx ~]# swapoff /dev/mapper/VolGroup00-LogVol01
使用swapon启用交换分区,此时查看交换分区的使用情况,你会发现used为0了
[root@testlnx ~]# swapon /dev/mapper/VolGroup00-LogVol01[root@testlnx ~]# free -m total used free shared buffers cachedMem: 64556 55385 9171 0 926 51406-/+ buffers/cache: 3052 61504Swap: 65535 0 65535[root@testlnx ~]# Swap分区空间什么时候使用
系统在什么情况或条件下才会使用Swap分区的空间呢? 其实是Linux通过一个参数swappiness来控制的。当然还涉及到复杂的算法。
这个参数值可为 0-100,控制系统 swap 的使用程度。高数值可优先系统性能,在进程不活跃时主动将其转换出物理内存。低数值可优先互动性并尽量避免将进程转换处物理内存,并降低反应延迟。默认值为 60。注意:这个只是一个权值,不是一个百分比值,涉及到系统内核复杂的算法。关于该参数请参考这篇文章[转载]调整虚拟内存,在此不做过多赘述。下面是关于swappiness的相关资料
The Linux 2.6 kernel added a new kernel parameter called swappiness to let administrators tweak the way Linux swaps. It is a number from 0 to 100. In essence, higher values lead to more pages being swapped, and lower values lead to more applications being kept in memory, even if they are idle. Kernel maintainer Andrew Morton has said that he runs his desktop machines with a swappiness of 100, stating that "My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful."
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.
有两种临时修改swappiness参数的方法,系统重启后失效
方法1:[root@DB-Server ~]# more /proc/sys/vm/swappiness60[root@DB-Server ~]# echo 10 > /proc/sys/vm/swappiness[root@DB-Server ~]# more /proc/sys/vm/swappiness10 方法2[root@DB-Server ~]#sysctl vm.swappiness=10永久修改swappiness参数的方法就是在配置文件/etc/sysctl.conf里面修改vm.swappiness的值,然后重启系统
echo 'vm.swappiness=10' >>/etc/sysctl.conf如果有人会问是否物理内存使用到某个百分比后才会使用Swap交换空间,可以明确的告诉你不是这样一个算法,如下截图所示,及时物理内存只剩下8M了,但是依然没有使用Swap交换空间,而另外一个例子,物理内存还剩下19G,居然用了一点点Swap交换空间。
另外调整/proc/sys/vm/swappiness这个参数,如果你没有绝对把握,就不要随便调整这个内核参数,这个参数符合大多数情况下的一个最优值。
Reply Like 0 View the author