Swap space is the area in secondary storage devices which temporarily holds memory pages that are inactive. Swap space is used when the system needs physical memory for active processes and there is insufficient unused physical memory available. In such a case inactive pages in physical memory are moved to the swap space therefore freeing up that physical memory for other uses.
In Ubuntu, the user is prompted to create a swap partition during OS installation. But have you ever felt that the space you have allocated is insufficient?
If yes, it is possible to create a new swap file and add it to the running system so that the total swap space will be increased.
I added 512 MiB of additional swap space to my system, creating a new swap file named NewSwap512.swap in the /mnt directory.
1. Creating a 512 MiB swap file and setting the permissions.
sudo fallocate -l 512m /mnt/NewSwap512.swap
sudo chmod 600 /mnt/NewSwap512.swap
sudo mkswap /mnt/NewSwap512.swap
2. Add it to the running system
sudo swapon /mnt/NewSwap512.swap
That will do, but this additional swap area is temporary
and will be lost after reboot.
To make it permanent, edit /etc/fstab
sudo gedit /etc/fstab
add this line to the end of the file
/mnt/NewSwap512.swap none swap sw 0 0