Gen 4 VPS & Dedicated Servers Help

Enable swap on my Gen 4 VPS & Dedicated Server

Swap on a server provides additional virtual memory when physical RAM is exhausted. It allows the system to temporarily store data on disk, preventing crashes or slowdowns due to memory limitations and ensuring smooth operation of applications. Swap can be enabled on your server through SSH.

Warning: This article covers an advanced technical topic. If the steps are completed incorrectly, it's possible to make unwanted changes to your site. Therefore, we strongly recommend creating a backup before you proceed. Please review the full Statement of Support to learn more about available support for additional products and services.
Warning: Relying heavily on swap can lead to performance degradation, as accessing data from disk is slower than retrieving it from RAM, potentially causing noticeable delays in application responsiveness. Therefore, we strongly recommend only using swap as a temporary solution while you work on optimizing your sites and server processes.
  1. Connect to your server using SSH.
  2. Switch to the root user.
  3. Create a file that will be used for swap:
    sudo fallocate -l 1G /swapfile
  4. Set the permissions for the file:
    sudo chmod 600 /swapfile
  5. Set up a Linux swap area on the file:
    sudo mkswap /swapfile
  6. Enable swap:
    sudo swapon /swapfile
  7. Using your preferred text editor command, open your /etc/fstab file, append the following line of code, and then save your changes:
    /swapfile swap swap defaults 0 0
  8. Verify that swap is active:
    sudo swapon --show

An output similar to the following will verify that swap is enabled:

/swapfile file 1024M   0B   -2 

More Info

Share this article