Swap space/memory is the virtual space in the system,which is pre-configured as swap partition/file. Swap space in Linux is used when the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.
To clear the swap memory on your system, you simply need to cycle off the swap. This moves all data from swap memory back to RAM.
We can see if the system has any configured swap by using swapon
swapon -s
If nothing is returned by the command, then the summary was empty and no swap file exists. Another way of checking for swap space is with the free command. If there is know swap , it will show SWAP is 0
The fastest and easiest way to create a swap file is by using fallocate
. sudo fallocate -l 2G /swapfile
dd
instead of fallocate. sudo dd if=/dev/zero of=/swapfile count=2048 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
swapon -s
Edit the fstab file sudo nano /etc/fstab
add the following entry
/swapfile swap swap sw 0 0
When you are finished adding the line, you can save and close the file. The server will check this file on each bootup, so the swap file will be ready for use from now on.