How do I set up swap memory? Print

  • 0

Swap is disk space the server uses as overflow when RAM runs low. To add a swap file over SSH:

  1. Create the file (e.g. 2GB): sudo fallocate -l 2G /swapfile
  2. Secure it: sudo chmod 600 /swapfile
  3. Format and enable: sudo mkswap /swapfile then sudo swapon /swapfile
  4. Make it permanent by adding /swapfile none swap sw 0 0 to /etc/fstab

Verify with free -h or swapon --show. A good starting size is roughly equal to your RAM. Note that OpenVZ-based VPS plans may not allow custom swap, in that case your RAM limit is fixed. On unmanaged plans this is your task; managed customers can open a ticket.


Was this answer helpful?

« Back