Skip to the content.

Add Swap Space To System

We can add swap space to the system by following method -

Check for existing swap space

$ sudo swapon --show

Create a new swap space

$ sudo fallocate -l 2G /swapfile
$ sudo chmod 600 /swapfile

Enable swap space

$ sudo mkswap /swapfile
$ sudo swapon /swapfile

Verify that the swap space exists

$ sudo swapon --show

Make swap persistent upon restart

$ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Source: DigitalOcean