Skip to main content

7. Swap memory

It is the best practice to setup swap memory on your server to keep it running healthy avoiding memory related issues. I generally prefer to create swap memory same as RAM size (check RAM using free -h). I have no idea what size it should be ideally.

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab # permanent swap

Reference URLs

  1. DigitalOcean community - I like this community
  2. StackOverflow community - I also like this community.
  3. Change swap