Swap space note

What is Swap?

Swap file systems support virtual memory, data is written to a swap file system when there is not enough RAM to store the data your system is processing.

Swap partition size

Old rule of thumb

swap: 2 * the-amount-of-RAM

So if a computer had 64KB of RAM, a swap partition of 128KB would be an optimum size. This rule took into the facts that RAM sizes were typically quite small at the time. Nowadays, RAM has become a cheap & affordable commondity, so the 2x rule is outdated.

What is the right amount of swap space?

Choosing the correct swap size is important. Too much swap space can hide memory leaks, also the storage space is allocated but idle. It can affect the system performance in general.

Follow the RedHat (CentOS 7x & RHEL 7) guide, the recommended size of a swap partition depending on the amount of RAM & whether you want sufficient memory for your system.

swap <= 10% * total-size-hard-drives && swap <= 128GB (if hibernation is allowed)
Amount of RAMRecommended swap spaceRecommended swap space if allowing for hibernation
< 2GB2 * the-amount-of-RAM3 * the-amount-of-RAM
> 2GB - 8GBthe-amount-of-RAM2 * the-amount-of-RAM
> 8GB - 64GB>= 4GB1.5 * the-amount-of-RAM
> 64GB>= 4GBHibernation not recommended

Common misconceptions & gotchas

Increasing swap size would increase performance

Swappiness

Using swap as emergency memory

References

  1. RedHad guideline

  2. Chris Down’s post

  3. Linux Hint - Understanding vm.swappiness