How To Enable Swap Space On Linux

Swap is storage space where the OS can temporarily store data that is normally stored in RAM when the RAM gets full. It can be useful to enable swap space to avoid out of memory errors.

Steps to enable swap on your server

  1. Use a machine with local SSD, such as c5d, r5d, i3, etc on AWS EC2 instances.

  2. Example commands to enable a 32G swap on the local SSD mounted on “/ssd” (run as root)

        # fallocate -l 32G /ssd/swapfile
        # chmod 0600 /ssd/swapfile
        # mkswap /ssd/swapfile
        # echo "/ssd/swapfile swap swap defaults 0 0" >> /etc/fstab
        # swapon -a

Note: The local SSD can be used for both swap space and disk cache.

by ObjectiveFS staff, May 15, 2020
ObjectiveFS is a shared file system for OS X and Linux that automatically scales and gives you scalable cloud storage. If you have questions or article idea suggestions, please email us at