Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space. Swap space can take the form of either a dedicated swap partition or a swap file. In most cases when running Linux on a virtual machine a swap partition is not present so our only option is to create a swap file.
FREE -H
$ free -h
run free -h TO CHECK MEMORY AND SWAP utilization
fallocate
$ sudo fallocate -l 1G / swapfile
We Create a file which will be used for swap with a size of 1 gb.
chmod
$ sudo chmod 600
SET THE CORRECT PERMISSIONS ON THE SWAP FILE.
mkswap
$ sudo swapon /swapfile
Enable the swap and Activate the swap file.
swapon
$ sudo swapon /swapfile
Enable the swap. Activate the swap file.
free -h
$ free -h
when we check the swap utilization again we can now see there is 1 gb allocated.