We can see if the system has any configured swap by typing:
1 2 |
sudo swapon --show |
You can verify that there is no active swap using the free utility:
1 2 |
free -h |
Check Available Space on the Hard Drive Partition:
1 2 |
df -h |
Create a Swap File, an amount equal to or double the amount of RAM on your system is a good starting point.
1 2 |
sudo fallocate -l 1G /swapfile |
We can verify that the correct amount of space was reserved by typing:
1 2 |
ls -lh /swapfile |
Enabling the Swap File, Make the file only accessible to root:
1 2 3 4 5 6 7 |
sudo chmod 600 /swapfile ls -lh /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo swapon --show free -h |
Make the Swap File Permanent, enable swap at every reboot:
1 2 3 |
sudo cp /etc/fstab /etc/fstab.bak echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab |
Adjusting the Swappiness Property:
1 2 3 4 5 6 7 8 |
# get current swappiness value by typing: cat /proc/sys/vm/swappiness # set the swappiness to 10 sudo sysctl vm.swappiness=10 # set this value automatically at restart sudo nano /etc/sysctl.conf |
At the bottom of the /etc/sysctl.conf
file , you can add:
1 2 |
vm.swappiness=10 |
Adjusting the Cache Pressure Setting:
1 2 3 4 |
sudo sysctl vm.vfs_cache_pressure=50 # set this value at each restart sudo nano /etc/sysctl.conf |
At the bottom, add the line that specifies your new value:
1 2 |
vm.vfs_cache_pressure=50 |