Ubuntu Memory swap
We can see if the system has any configured swap by typing:
sudo swapon --showYou can verify that there is no active swap using the free utility:
free -hCheck Available Space on the Hard Drive Partition:
df -hCreate a Swap File, an amount equal to or double the amount of RAM on your system is a good starting point.
sudo fallocate -l 1G /swapfileWe can verify that the correct amount of space was reserved by typing:
ls -lh /swapfileEnabling the Swap File, Make the file only accessible to root:
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
free -hMake the Swap File Permanent, enable swap at every reboot:
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabAdjusting the Swappiness Property:
# 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.confAt the bottom of the /etc/sysctl.conf file , you can add:
vm.swappiness=10Adjusting the Cache Pressure Setting:
sudo sysctl vm.vfs_cache_pressure=50
# set this value at each restart
sudo nano /etc/sysctl.confAt the bottom, add the line that specifies your new value:
vm.vfs_cache_pressure=50