Fog Creek Software
Discussion Board

A Question on Memory - How much Swap is desirable

Memory: 2048M real, 1594M free, 144M swap in use, 1943M swap free

The above is a snapshot of memory usage on a server I am monitoring.

Some times the free memory goes almost to zero and the swap kicks in - the swap has also almost gone dangerously low.

Short of spending $ to get memory, how much swap can I theoretically increase before peerformance really takes a hit?

Vin Diesel
Thursday, August 19, 2004

As soon as the machine starts to "swap" , thats when the performance takes the hit.  Run out of swap and no telling what will happen ( but it will not be good)

Thursday, August 19, 2004

It's recommended that you have as much swap as real memory plus a little, which is what the numbers you described imply.  I never hope that a system needs that much swap, and I tend to set it much lower.

If the size of the swap is being pushed, then you should wonder if the server is overloaded.

Frank "Grimey" Grimes
Thursday, August 19, 2004


It really depends on what the machine is doing? ... how many concurrent users? ... what type of service does it run?

I've seen a rule of thumb that said swap should be 3 times the physical memory. However, how much the swap gets used really depends on the type of usage.

Thursday, August 19, 2004

I'm with mouse on this.  Never let a high performance server swap.

Thursday, August 19, 2004

Make sure you realize the difference between paging (normal and expected) and swapping ( bad, bad)

Thursday, August 19, 2004

If you got two gigs and only 1 gig of ram is ever used you could get by with little swap.  The closer you are to your limit of ram the more you want to make it (Within reason)  The figures of 2 or 3 times ram come from the days when a large computer had 64 mb of ram.  We are reaching a point where 6 gb of swap may be a TAD EXCESSIVE for 2 GB of ram.

Haley's vomit
Thursday, August 19, 2004

A figure I often hear today is 1.5 x RAM. I think Win XP and presumably Server 2003 can dynamically increase the swapfile if the need arises. My swap started out as 1.5 x RAM but XP has occasionally popped up 'windows is low on virtual memory. your swap file size is being increased' and it's up to 2 x RAM now.

I would get more memory but it's a laptop with only 2 slots, both taken with 256 modules, so I can't really add any more without replacing what's in there, and that's expensive!

James U-S
Friday, August 20, 2004

Let's be more explicit. The bad thing about swap is not that it's being used at all, but when things are being thrashed in and out of it.

For example, suppose you have an application with a large but well characterised memory leak and a necessarily long run time. It leaks 50MB per day, and you'd like to run it for as many weeks as possible without a restart. So long as whole pages are being leaked this will gently push 50MB per day into swap, until you run out of swap, so you can add a gigabyte of swap to the machine and go for three weeks, or two gigabytes for six weeks, etc. In that scenario using LOTS of swap makes sense, up to the process size limit where your leaky app exhausts its finite supply of unique addresses (commonly 1-3GB). Of course, someone, somewhere should be fixing the leak meanwhile...

On the other hand if you have an application where a certain amount of memory is actively needed for each interactive user, and you reach the point where the total memory needed reaches or exceeds the RAM, then the system will be constantly paging memory to and from the swap. If you're lucky this frustrates users and they quit, freeing up memory, if you're unlucky they thrash away harder trying to get something done, and the machine becomes unusable for everyone. In either case obviously you need to buy more RAM, or if necessary upgrade to newer hardware (and more RAM).

So don't worry so much about in-use stats, look at the IO metrics, and see how much disk access is being done to that swap, and look at CPU usage to see how much of the time is spent waiting for memory from swap. This is time that would be saved (for your users) if you bought more RAM.

Nick Lamb
Friday, August 20, 2004

*  Recent Topics

*  Fog Creek Home