Before working make sure that system has already swap enabled. If there is no swap, you will get output header only.
sudo swapon -s
Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally, it recommends that swap should be equal to double of installed physical memory.
I have 1GB memory in my system. So I am creating swap of 2GB in size.
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
Now make is swap usable file using mkswap
command.
sudo mkswap /swapfile
Now setup the swap for system using swapon
command.
sudo swapon /swapfile
Now again check that swap is enabled or not.
sudo swapon -s
Append the following entry in /etc/fstab
file to enable swap on system reboot.
sudo nano /etc/fstab
/swapfile none swap sw 0 0
Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.
sudo nano /etc/sysctl.conf
vm.swappiness=10
Now reload the sysctl configuration file
sudo sysctl -p