Re: [Hampshire] Swap versus RAM size (was: I just have to te…

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Swap versus RAM size (was: I just have to tell someone...)

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x57ea5100.hantslug.org.uk.7684': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sun Oct 26 01:09:12 2008 BST
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Sun, Oct 26, 2008 at 12:11:50AM +0100, Keith Edmunds wrote:
> On Sat, 25 Oct 2008 21:40:15 +0000 (GMT), b.stevens611@??? said:
>
> > I've always used the same size swap space as memory... I remember
> > reading somewhere that that was the way to do it.)
>
> It's about time this particular myth was buried (and the "swap should be 2
> x RAM" one). Suppose you had a system that had a performance issue, and
> you found that it was swapping a lot. For the sake of example, let's
> assume 1Gb RAM and 1Gb swap. When you look closer, you see the swap file
> is usually around 40%-60% used, peaking at 80%. That means the system is
> trying to use around 1.5Gb of RAM, so you fit an extra 1Gb to give 2Gb in
> total.
>
> What now would be the logic in increasing the swap file size? (I'm
> assuming a constant-ish load: if the load is increasing then you may well
> need more memory of one sort or another).
>
> Historically, it was recommended that the swap size should be 2 x RAM.
> However, that was in the days when (real) memory was very expensive, and
> it was relatively cheap to have a larger swap file. Perhaps that advice
> could have been better written, "The amount of RAM you need is at least
> 50% of the swap space you have". /That/ makes sense, because real memory
> is much faster; if you run short of memory again, increasing the RAM
> doesn't break that guideline, and increasing the swap suggests that,
> really, you need a increase in RAM too, which again seems logical.
>
> Maybe someone else has a different perspective on this?


I believe that there were (that's *were*) good technical reasons
for the 2*RAM recommendation, back when it was first made, related to
the performance of the algorithms used to manage swap space. Those
algorithms are long gone, and the recommendation no longer applies.

However, having *some* swap is usually a good idea, as it gives you
a small buffer zone in the system to kill a memory-hog application as
the whole machine slows down, before you exhaust the available memory.

Of course, that doesn't help always, either. Sometimes, the kernel
OOM killer doesn't kill the right thing (or the task respawns). I've
had systems collapse under the weight of many apache processes before
-- still technically responding to things, but so slow that TCP
connections time out, and you have to wait 5 minutes to get a reponse
to a keypress on a terminal.

On the other hand, swap is useful if you have a couple of
applications loaded that are only used occasionally, and the latency
of swap doesn't matter too much -- then they can be swapped out,
leaving more RAM for other things.

Hugo.

--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- "You know, the British have always been nice to mad people." ---