For When You Can't Have The Real Thing
[ start | index | login ]
start > Linux > Swap Size

Swap Size

Created by dave. Last edited by dave, 15 years and 203 days ago. Viewed 9,326 times. #1
[edit] [rdf]
labels
attachments

How big a swap partition do I need?

The canonical answer is "RAM X 2". This is for historical reasons.

In early Unixes (SunOS, e.g.), the memory manager was dumb and preallocated swap space sufficient to swap your entire process out if it became necessary, and it really did want contiguous. Running out of swap was common, even if it was really never used, and the "rule" to avoid that problem was 2xRAM. Further, if you had two swap partitions, or a partition and a file, your process stayed in whatever swap it started in and did not split across both. You could be out of swap space and still have a completely empty swap file.

However I've found that this rule leads to stupid amounts of swap. Do you really need 8GB of swap on a 4GB system? The real answer is: it depends.

RAM is cheap

My theory these days is: If you have a working set that won't fit in RAM, you need more memory. If you need more memory, buy more RAM.

I find computers become practically unusable once they start thrashing more than about 512MB, and I've demonstrated to some of my engineers that for working sets that thrash a GB or more it is faster to stop the job, go buy and install more RAM, then restart the job, than it is to just wait for the job to finish in the first place.

This is even more true of large machines. I've run memtest86 on a 32GB system, and it only completed three and a half full cycles over a 60-hour period. Thrashing a dataset of that size through a hard disk would take months.

Unless an engineer can make a really good case (and I mean really good) then workstations get 1GB of swap. Servers and compute nodes get 2GB.

Virtual machine servers get almost no swap (512MB or less). This forces people to be careful about not overcomitting RAM for virtual machines.

no comments | post comment
This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful:


snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt