决定修改swap大小
首先在空间合适处创建用于分区的swap文件
dd if=/dev/zero of=/swap/swap bs=1024 count=4194304
将目的文件设置为swap分区文件
mkswap /swap/swap
激活swap,立即启用交换分区文件
swapon /swap/swap
查看
free -m
开机时自启用
修改文件/etc/fstab中的swap行
/swap/swap swap swap defaults 0 0
swappiness
check
cat /proc/sys/vm/swappiness
edit
sudo vim /etc/sysctl.conf
apply
sudo sysctl -p
Ubuntu: What is swappiness
The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.
swappiness can have a value between 0 and 100.
swappiness=0
:- Kernel version 3.5 and newer: disables swapiness.
- Kernel version older than 3.5: avoids swapping processes out of physical memory for as long as possible.
swappiness=1
:
Kernel version 3.5 and over: minimum swappiness without disabling it entirely.swappiness=100
:
Tells the kernel to aggressively swap processes out of physical memory and move them to swap cache.
References:
- http://en.wikipedia.org/wiki/Swappiness
- https://askubuntu.com/questions/103915/how-do-i-configure-swappiness
The default setting in Ubuntu is swappiness=60
. Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation. A value of swappiness=10
is recommended, but feel free to experiment.
In server, set swappiness=1
.