Swap is a special file on the hard drive, to which the OS will dump unnecessary objects from the RAM when RAM is getting overflown.

On the server, swap drastically improves the overall system performance and helps you store more processes in memory. First, you need to connect to the server via SSH.

How to connect to the server

  • Open the terminal (via the User Menu or Alt+Ctrl+T).
  • Enter ssh username@server_ip_address
  • Enter your password.

Now let’s check if the server is using swap

How to check if Ubuntu 16.04 server is using swap

  • Enter sudo swapon –show
  • If you have received any output — you are using swap. If there’s none — you need to enable it.

How to enable swap on Ubuntu 16.04 server

  • Enter sudo fallocate -l 1G /swapfile. Instead of 1G put in the amount of storage you are willing to dedicate to swap. Generally, it should twice the amount of RAM you have.
  • Give your server rights to access swap: sudo chmod 600 /swapfile.
  • Mark the new file as a swap file: sudo mkswap /swapfile.
  • Enable swap: sudo swapon /swapfile.
  • Make it constant: echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab
  • Make your server use swap only when it is necessary: sudo sysctl vm.swappiness=10
  • Reboot the server (not necessary, but recommended).