swap space??

Rick Thomas yellowdog-general@lists.terrasoftsolutions.com
Mon Aug 19 13:28:01 2002


As others have said, how much space to allocate to swap is very
dependent on your configuration and workload.  So it tends to be a
religious issue.  Here are some facts based on 25 years of UNIX system
administration experience.

1) In the olden days, when RAM was small and expensive, and so were
disks (but less so), and RAM was quick, but disks were slow relative to
human timescales, UNIX allocated shadow swap for every block of virtual
RAM it allocated.  This way, when you needed to swap out a program
(which was often) you already had the space allocated and didn't need to
waste time finding where to put it.  This lead to the rule of thumb that
you needed three or four times as much swap space as you had RAM for a
typical time-sharing system.  More (sometimes _lots_ more) if you had a
transaction/database system with lots of infrequently active users.  The
figure of three-or-four came from the observation that the typical
timesharing user spend 75% of their time thinking, and 25% waiting for
the computer.  Faster CPUs made for a larger ratio ot think to compute,
hence a larger ratio of swap to RAM.

2) Today, all those factors have changed.  So modern UNIX systems don't
allocate swap space until they need it -- on the expectation that they
will never need it.  Cheap RAM means you don't want to swap at all if
you can avoid it.  Cheap, fast, disk means that even if you do swap
occasionally, it won't be a big deal.

Frequent swapping is still going to be a problem and should be addressed
by system tuning (such as buying more RAM, or spreading the swap space
out onto multiple disks) or tuning the workload.  (There is usually much
more to be gained by tuning the workload than by throwing resources at
an algorithm that scales poorly!)

For a typical time-sharing system or desk/lap-top workstation, you don't
need more swap than RAM (Probably, you can get away with _less_ swap
than RAM.  I've seen systems run quite happily with no swap at all!)  On
the other hand, disk is absurdly cheap and there are infrequent (but
real) situations when having lots of swap space (and lots of patience
while the system sorts itself out) can get you safely out of a situation
that would have otherwise resulted in a system crash.  It's your system
-- you make the trade-off decisions.

3) All of that having been said, there are types of systems that
_require_ large swap space allocations, even today.  Here's an example
from my personal experience:

I have a server at home (a beige G3 with 192MB RAM and 48 GB disk,
running YDL 2.2) that provides lots of services (i.e. runs a whole mess
of daemons) to a flock of Macs and PCs scattered throughout the house. 
The client machines are used several times a day by their various
owners, but have long periods of inactivity (You can't spend _all_ your
life hacking.  You've got to eat and sleep sometime!)  During those
periods of inactivity, the server does various background tasks, such as
download mail, run various housekeeping cron jobs, etc.  In other words,
the usage is sharply bi-modal.  This relates to swap space allocation
thus: When in one mode, the processes for the other mode reside on swap.
 So this system absolutely requires at least twice as much swap space as
RAM.  I have 1GB allocated, just to provide a cushion over the 400MB
that this paragraph's discussion would say is the absolute minimum.

Enjoy!

Rick