Linux: Should You Use Twice the Amount of Ram as Swap Space?
November 21, 2008 (2:30:00 PM) - 1 month, 2 weeks ago
Share
a>
Print
Comments
Linux and other Unix-like operating systems use the term "swap" to describe both the act of moving memory pages between RAM and disk, and the region of a disk the pages are stored on. It is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions. Now, many admins (both Windows and Linux/UNIX) follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. Let us say I've 32GB RAM, should I set swap space to 64 GB? Is 64 GB of swap space really required? How big should your Linux / UNIX swap space be?
Linux: Should You Use Twice the Amount of Ram as Swap Space?
Posted by: Fletch on November 21, 2008 03:27 PMNow, servers can have plentiful amounts of RAM, and realistically, for the types of programs we run, so can workstations. So how does one determine how much SWAP is needed? For one, you have to ask yourself, "do I need to collect dumps of what is in RAM in a system crash?" If you have really good support, or you are a developer that wants to collect what was actively happening before a system crash, you should have the same amount of SWAP as you do RAM, because you are going to need to fit everything that was actively running in SWAP (granted this is usually more actively used in Solaris then Linux, but regardless). Secondly, the way to determine how much RAM you actually need is to find out what the expectations are for all the applications, services, etc that you expect to be loaded and running worst case. If this is a workstation, open every application that you have, open as many tabs open in that browser that you yourself commit to using, and as many pictures open in that photo editing program that you want to use...open them all at once. Find out the total memory foot print (and granted, you would have to do this on an already running machine. Once you find the total footprint, then adjust your SWAP size accordingly to handle this in the worst case scenario if it can not all fit in RAM. Most people will shut down their office application before firing up that game, but you shouldn't if you want to handle worst case scenarios. By getting these values, you can set your SWAP size to what you should need, (and you may want to leave some extra space in case applications continue to grow, which may be why it is a good idea to have SWAP be encapsulated in a volume manager so that way you can grow this volume as need be if and when you need more space, but you may rather increase the amount of RAM you have later as a better alternative providing your host can accept more).
Anyway, those are generally what you would do to better approximate the amount of RAM needed. Similarly, you can tune these values in server space by using load testers and setting the value of connections, etc to realistic values in your environment, and after tuning these values, you can get a better idea of what your capacity of growth will be on your server, and it also allows you to begin tuning to get the most out of the RAM of the host. Maybe tune down the stack sizes of those threads, etc. Hopefully, this information will be more useful then simply saying, "well...memory management is better in Linux now", but regardless of what operating system you use, these are the general guidelines for knowing what you need.
Haz
#