St. Louis Web Developer & User Interface Designer

System running out of memory: create a swap file

If you have a virtual private server (VPS) and are getting errors like “system running out of memory,” you may want to double check whether you’re using a swap volume or file.

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. (source)

l have about 17G left, so that’s plenty. Online users generally agree that a good amount of swap space is at least the size of the available RAM, if not 1.5 or 2 times the amount (up to 2GB). You can check how much RAM you have on your server with the following command:

4. Enable swap file

5. Auto-enable swap file

Should you restart your VPS, the swap file would have to be enabled again, which is why we’re going to add an entry into the fstab configuration file to automatically enable the swap file for us on boot.