You can also control at which point the system starts to use swap memory. This will tell you what is the current value in your computer:
cat /proc/sys/vm/swappiness
Linux default used to be 60. Roughly speaking, this means that the computer will start using the swap partitions when as little 40% of RAM is being used. This was a safe default for old machines. However, if you have plenty of RAM, you can reduce the swappiness.
On the fly:
sudo sysctl vm.swappiness=10
sudo swapoff -a
sudo swapon -a
Or permanently by adding vm.swappiness = 10 to /etc/sysctl.conf (for Debian).
# free -m
total used free shared buffers cached
Mem: 64410 43406 21004 0 219 24696
-/+ buffers/cache: 18489 45920
Swap: 4095 4091 4
# cat /proc/sys/vm/swappiness
60
# echo "vm.swappiness=10" >> /etc/sysctl.conf
# sysctl -p
# swapoff -a -v
swapoff on /dev/sda2
# swapon -a -v
swapon on /dev/sda2
swapon: /dev/sda2: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/sda2: pagesize=4096, swapsize=4294967296, devsize=4294967296 # free -m
total used free shared buffers cached
Mem: 64410 47661 16748 0 222 24721
-/+ buffers/cache: 22717 41692
Swap: 4095 0 4095
swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,
swappiness=100的时候表示积极的使用swap分区,
并且把内存上的数据及时的搬运到swap空间里面。