Categories: LinuxUbuntu

How To Add Swap Space on Ubuntu 20.04 or 20.10

One way to guard against out-of-memory errors in applications is to add some swap space.

What is Swap?

Swap is a portion of hard drive storage that has been set aside for the operating system to temporarily store data that it can no longer hold in RAM. This lets you increase the amount of information that your server can keep in its working memory, with some caveats. The swap space on the hard drive will be used mainly when there is no longer sufficient space in RAM to hold in-use application data.

Swap space can take the form of either a dedicated swap partition or a swap file. Swap should not be seen as a replacement to physical memory. Since swap space is a section of the hard drive, it has a slower access time than physical memory. If your system constantly runs out of memory, you should add more RAM.

How to calculate Swap size?

The size of swap file depends on how much RAM your system has.

  • Systems with less than 2GB RAM – 2 times the amount of RAM
  • Systems with 2GB to 8GB RAM – the same size as the amount of RAM
  • Systems with more than 8GB RAM – at least 4GB

Why is Swap needed?

  • If your system has RAM less than 1 GB, you must use swap as most applications would exhaust the RAM soon.
  • If your system uses resource heavy applications like video editors, it would be a good idea to use some swap space as your RAM may be exhausted here.
  • If you use hibernation, then you must add swap because the content of the RAM will be written to the swap partition. This also means that the swap size should be at least the size of RAM.
  • Avoid strange events like a program going nuts and eating RAM.

Does it necessary to create a Swap if RAM size is more than 16GB, 32GB, 64GB?

If you have 32GB or 64 GB of RAM, chances are that your system would perhaps never use the entire RAM and hence it would never use the swap partition. Allocating a couple of GB for swap will provide an extra layer of ‘stability’ if a faulty program starts misusing RAM.

Emre KARABULUT

Hi, I’m Emre KARABULUT, 29, and I am the owner of a small (but perfectly formed) design studio called Minimalist Art & Design based in Istanbul, which specialises in Blog and User Interface design. I help entrepreneurs and small business owners create a unique brand and online presence which gives them a powerful platform to reach out to their customers and markets.

Recent Posts

Authenticating with the Apple Search Ads API

There are many methods for using APIs. In order to understand it better, lets take…

4 years ago

Install Docker-Compose on Ubuntu 20.04 or 20.10

Docker Compose is a tool that allows you to run multi-container application environments based on…

4 years ago

Shopware 6 – Local installation in Ubuntu 20.04 or 20.10

After the creation of development environment your setup fulfills the Shopware 6 requirements. If you…

4 years ago

Shopware 6 – Docker installation in Ubuntu 20.04 or 20.10

After the creation of development environment your setup fulfills the Shopware 6 requirements. If you…

4 years ago

Shopware 6 – Installing System Requirements in Ubuntu 20.04 or 20.10

To create a development environment in fresh install of Linux - Ubuntu 20.04 (Focal Fossa)…

4 years ago

Install Docker on Ubuntu 20.04 or 20.10

Make sure your Ubuntu is up to date and patched. $ sudo apt update $…

4 years ago