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

Top Page

Reply to this message
Author: Tom Dawes-Gamble
Date:  
To: hampshire
Subject: Re: [Hampshire] Swap versus RAM size (was: I just have to tellsomeone...)

On Sun, 2008-10-26 at 00:11 +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.


Yep I'd agree.

Here is my take on it.

My memory is not was it used to be (If you forgive the pun ;-)

I seem to remember when I worked on TI System V a binary would have what
was called a request block. The request block gave details of the
memory requirements for the process to start up. Before the process
could start that much memory would be reserved in swap. If the required
amount of swap could not be reserved then the process would not start.

So if swap was not a large as memory you would not be able to use all of
the memory. Of course not all memory is used by processes some is for
the kernel and some for buffer cache. So you could get away with swap <
memory but the chances are in those days you would run out of memory and
swap unless you had swap larger than memory.

When you run out of swap something has to give and that is normally up.

Things have become a bit better these days for example text pages don't
change therefore you can just delete them from memory and reload them
from the binary. So now with Swap == Memory you can run a lot more
processes before you run out of swap. Even so if you run out of swap
the system is going to give up or at least things are going to go a bit
wrong.


I'm not sure if Linux does something similar these days. HPUX for
example has the option to use "Psuedo" swap. This means that real
memory is allowed to be counted in the size of the Swap. This was
explained as being similar to football teams. If you think of the pitch
as memory and the bench as swap. The processes (players & substitutes)
have to go somewhere. Memory (the pitch) is only large enough to hold
11 players thus Swap (the bench) must be large enough to hold all of the
substitutes plus one. Thus to replace a player on the pitch you take
him off the pitch and put him in the spare seat on the bench and then
take a Substitute off the bench and put her on the pitch.


If you observe that your system is swapping then moving the swap to a
bigger, better, faster device is not the answer to your problem.
The answer is more memory.


If you are using swap then it depends what you are using it for.

If for example the users arrive at work in the morning logs on and then
start their applications causing their shells to be paged out and they
stay in the Apps all day until they go home in the evening, they quit
the Application the shell gets paged in and they quit the shell. That's
not a bad situation.

On the other hand if the users are developers they log in and then start
an editor. That causes the shell to get paged out, They save and quit
the edit the shell is paged in then they compile the program again
causing the shell to be paged. After compilation the shell is paged in
again and now the compiled program is run to test is again causing the
shell to be paged. In this environment performance could be a little
sluggish.


IMO it depends how tight your budget is. If you have 2g of swap and
only ever use 500k then your wasting most of the swap space. On the
other hand only having 1m of swap might be sailing a bit close to the
wind. Even so if you never go over 512k a 1m swap will perform as well
and as reliably as a 2m 10m 100m or 1g swap.

Increasing the size of swap will not improve performance.
If your system is swapping then adding memory will improve your
performance but will not increase the requirement for swap.

Personally I use the rule:-

Swap needs to be bigger than the sum of all of the pages you need to
have swapped out at any one time.

If I look at my workstation at the moment top shows.

========================================================================
top - 20:26:32 up 15 days, 23:26, 16 users,load average: 0.11,0.08, 0.08
Tasks: 187 total, 1 running, 186 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.7%us,  0.3%sy,  0.0%ni, 98.8%id,  0.0%wa,  0.0%hi,  0.0%si,
0.2%st
Mem:    964608k total,   893708k used,    70900k free,    46868k buffers
Swap:  2031608k total,      172k used,  2031436k free,   223668k cached
========================================================================


The systems performs well for me and looking at swap user 172k I would
say there is no strain on the memory. The swap is 1.9g as decided by
the installer as memory x 2. I have plenty of free space in my file
systems 250g free so I'm not that bothered that 2g of space is used for
swap. If the disk space was starting to get squeezed then shrinking
Swap to 500 Mg is not the answer even if it were only a 40g drive. The
answer is a bigger drive or additional drive(s).

A while back I was involved with a system that had failed due to a
problems with swap. The system had been running faultlessly for many
weeks and then it just stopped. The problem with swap was that the swap
partition had not been formatted. So in all that time the system had
not needed to swap. Of course as soon as it needed to swap bang!

Hope that's useful for you.



regards,
Tom.