Swap size in Ubuntu?

Published: October 12, 2022

Swap size in Ubuntu?

When RAM isn't able to handle process requests due to insufficient space then all the inactive pages in RAM move to Swap. This frees up the space in RAM and subsequent requests are properly dealt with. If Swap isn't available then, the processes would begin to fail. Certainly, this is not something we want.

Next question which arises here, what would be the ideal Swap size? Or, if we have ample amount of storage space then can we have allocate more to Swap space than suggested? The answer to the first question is - There is no ideal size for Swap space. It is advisable not to allocate less space to it as that would defeat the purpose of having a Swap space altogether. Besides, we also can't allocate disproportionately large amount to it. There wouldn't be any noticeable improvement.

Swap size in Ubuntu?

Different Linux distributions suggests different Swap size. In case of Ubuntu - If you have less than 1GB of RAM then, Swap size should be equal to that of RAM. Besides, maximum Swap size should be twice the amount of RAM available. Allocating more than that would not yield much.

But, for those systems which have more than 1GB RAM.

  1. If you want to use Hibernation feature then minimum size of Swap space should be equal to that of your RAM + Swap space without Hibernation.
  2. Without Hibernation, the minimum should be calculated by taking square root of RAM and then round off the outcome. And, the maximum should always be equal to twice the RAM size.

We explain the above with the help of an example. Let's say we have 3GB of RAM available then, Minimum value of Swap without Hibernation, we take √3 = 1.732 GB. Rounding it off, comes out - 2GB.

Swap space beyond the maximum values specified above would hardly have an impact. Reason - Physical disks are much slower than RAMs. Therefore, any addition beyond a point is not going to make things faster for us.

In conclusion, Swap space comes to rescue when RAM can't handle process requests due to insufficient available space. Allocating appropriate Swap space ensures that our system resources are optimally utilized.