This article covers how we can add and maintain swap space in the ubuntu system. Swap space can take the form of either a dedicated swap partition or a swap file. Typically, when running Ubuntu on a virtual machine, a swap partition is not present, and the only option is to create a swap file.
To Adjust the Swappiness Value:
Swappiness is a Linux kernel property that defines how often the system will use the swap space. It can have a value between 0 and 100. A low value will make the kernel to try to avoid swapping whenever possible, while a higher value will make the kernel to use the swap space more aggressively.
On Ubuntu, the default swappiness value is set to 60. You can check the current value by typing the following command:
$ cat /proc/sys/vm/swappiness
To Remove a Swap File:
1. First, deactivate the swap space:
$ sudo swapoff -v /swapfile
2. Next, remove the swap file entry /swapfile swap swap defaults 0 0 from the /etc/fstab file.
3. Finally, remove the actual swapfile file using the rm command:
$ sudo rm /swapfile