Wednesday, November 19, 2008

2x RAM for swap space? huh?

I came across an article here which sparked my interest in blogging about this today. Yeah i know "Big can of worms"

I am calling this "swap talk" - This kind of talk has been around since the swap file was introduced, and the kernel limits on swap were introduced. (Meaning a very very long time. Say Kernel 1.x, 2.x)

It seems i answer this question quite a bit in my travels. The truth is many admins follow an _OLD_ rule of thumb that your swap partition should be twice the size of your main system RAM. I have heard some other old rules such as... swap == ram, and Swap space == 2GB size (if RAM > 2GB). There are lots more, just google it. :)

Here is what it boils down to.
How much do you know your user space applications?

Here are the Methods i like to use.

Workstation with 4GB of RAM:
4GB swap
why? because my user space apps are VMware Workstation for one, which if I have say 4 or 5 VM's running then I'm going to be swapping, so it makes sense. I could probobly get away with 2GB though. Most of the time you will be able to get away with very low amounts of swap space for Workstations if you have about 2GB of RAM available.

Server:
swap == ram ( if ram <= 4GB ) || swap == 4GB ( if ram > 4GB )

I like to use this rule with just about everything. I think its a good starting point and fits mostly everything, but it leads to another rule mentioned above "How much do you know your user space applications?"

So lets say you have a Database that is pretty consistent high load... Oracle and others might suggest 8GB of swap space.

Maybe you have a JBoss Server load balanced and it has high load spikes during certain times of the day, but not exactly consistent. So when you receive that load spike you all of a sudden see kswapd go mad with your CPU and your system comes to a crawl. Ummm.. well you might want to get more RAM or a bigger server to handle that load.

Which brings me to another method. Throw more ram in your system. You might not like swapping at all and if you see your application swapping then just throw more ram in your system.

Absolute Bottom line no matter which method your using. "How much do you know your user space applications?" Learn how your user space applications are using memory and adjust your systems accordingly.

I would like to know your methods. Please post comments on your methods.

1 comment:

Unknown said...

I understand the old 2xRAM Swap concept and what I take away from your blog is, know your apps, but 4 GB Swap is the largest a Swap should ever be.

OK, sounds reasonable to me but I am left wondering a few things.

1. Would you mind expounding on how you arrived at your 4 GB max Swap rule?
2. What about the concept of a laptop hibernating and needing to swap all that is in RAM. Lets future proof this a little and say a 64 bit laptop with 8GB RAM?

Thanks!