amazon ec2 instance doesn’t have swapfile by default:

sudo swapon -s

the output should show no swap files. we need to add a swap file for better instance performance.

we can create a 4gb file by typing:

sudo fallocate -l 4G /swapfile

now we need to set permissions to file, so only root can write to it.

sudo chmod 600 /swapfile

now let’s make a swap

sudo mkswap /swapfile

finally we need to enable a swap file

sudo swapon -s

now the output of >sudo swapon -s will show that you have a 4gb swap file.