Wednesday, December 3, 2008

Quickly - Linux Swap space sizing

It's no surprise that many system administrators are still using this simple rule of thumb for sizing their system's swap size:
  • the swap space should be as large as twice amount of system operating memory
I belonged to them. But is it still really necessary to follow that rule when our machines are equipped with gigabytes of RAM now? Sure, it is waste of disk space. If I have a machine with 32 GB RAM, the swap space should have at least 64 GB!

This rule of thumb really held in the past but nowadays the Linux kernel and its memory management are more mature and well optimized to be able to work without any swap space. Even, if you use a swap file instead of dedicated swap partition, it should have nearly the same performance as swapping to partition. So, do we have a newer replacement for it? In genereal, it is recommended to remember the following:
  • if the machine has less then 2 GB of RAM, the swap space should have the size of it
  • if it has more, the swap space should have 2GB
In my opinion, you can't screw anything up if you set the swap space to 2 GB everytime. It has to be enough for every common situation according to the above rules. In more special scenarios, like database or web servers, it is better to follow related tuning guides.


Martin Vincenc said...

generally speaking, if the machine has 16GB RAM, the swap size should be 18GB.

The magic formula is:
If M < 2
S = M *2
S = M + 2

more info @

Martin Vincenc said...

But, i must admit, anaconda installer should do the math for you. However, it uses the old formula noone is using these days. Let's create a RFE (Request for Feature Enhancement) @ RED HAT!

Martin Vincenc said...

final thougt, swap size essentially changes when we are installing Dom0s, or other virtualization platforms. 1GB swap is there enough size to set, depending on situation. M

Anonymous said...

you have a nice site. thanks for sharing this enormous resources. keep it up. anyway, various kinds of ebooks are available here