I've been in the UNIX and GNU/Linux world since 1999. Back then, hard drives were barely passing double digits in GB, and RAM was PC100 speed at roughly 128 MB max. In fact, it wasn't uncommon for most systems to have 32 MB of RAM with an 8 GB hard drive. And we ran GNOME, which had barely released, and KDE on these machines!
However, when installing the operating system, is was a general rule of thumb that the size of your swap file should be 2x the amount of RAM. So for a 32 MB RAM system, this meant dedicating 64 MB of disk to swap. This wasn't a big deal back then. After all, hard drives were 8-10 GB in size. What's 64 MB?
Fast forward just a few years, and it wasn't long before this recommendation became unreasonable. After all, if you had 4 GB of RAM in your laptop (which I had in my Lenovo T61 for years) and a 100 GB hard drive, this meant dedicating 8 GB of hard drive space to swap- roughly 1/10 the drive size! So, the recommendation shifted a bit to 1.5x the amount of RAM, or 6 GB of swap in my T61.
Now look at to today with DDR3 RAM sizes and the popularity of SSDs. My server has 32 GB of RAM, and 2x60 GB SSD drives in a Linux software RAID mirror. So, given the recommendation of 2x the amount of RAM, this would mean 64 GB of swap on a 60 GB disk. Given the recommendation of 1.5x the amount of RAM, this would mean 48 GB of swap on a 60 GB disk. Something tells me we need to re-evaluate the recommendation.
When I started training for Guru Labs, I started re-evaluating the recommendation. In fact, I started debating if I even NEEDED swap. After all, swap is nothing more than a physical extension of the installed RAM on your system, it just resides on disk, which is slow. So, for my laptop, I didn't bother with it. Instead, I upgraded my RAM to 8 GB, which the board supported. I then started telling students my own personal recommendation on swap sizes:
Unless you have an application that has advanced swapping algorithms, and needs more swap, 1-2 GB of swap should be more than sufficient for most situations. Otherwise, install more RAM, and don't even bother with it at all.
Now, there are some caveats. If you would like to hibernate your system, you may need as much swap as you have RAM, seeing as though hibernation implementations typically flush all of the contents of RAM into the swap/paging file. This could be useful for laptops. Also, there are some software applications out there which can swap in and out very efficiently, leaving active RAM available for the running software. The Oracle database software comes to mind here.
Swap can be part of a healthy system, and having it installed isn't "a bad thing", unless the system is thrashing of course. But it also isn't required, which I think some people aren't aware. You don't NEED swap. It's just like the laundry basket in your house. Rather than leaving dirty clothes all over the house, you can put them neatly in one place, out of the way. But the laundry basket isn't required to do the laundry.
{ 12 } Comments