[geeks] Swap Memory..

Greg A. Woods woods at weird.com
Sun Oct 20 12:06:04 CDT 2002


[ On Sunday, October 20, 2002 at 06:40:55 (-0700), Lionel Peterson wrote: ]
> Subject: Re: [geeks] Swap Memory..
>
> This is an emotional issue for many, but unless you know you need to be
> able to handle a working set of applications with up to 6 Gig of
> memory, I would think real hard about going above 2 gig of swap.

It's often very difficult to predict how much swap one might need in
worst case situations.  Having lots of extra swap is rarely a waste
given the relative sizes of the rest of your secondary storage
capacities these days.  When you've got hundreds of GB of filesystem
space or more it's nothing to throw a couple of GB at swap.

For example even on a small server with 4x4GB drives and only 320MB RAM
I put 500MB of swap on each spindle.  Now that I've added some much
bigger RAID arrays to that machine the amount of swap seems tiny and
insignificant.

As it is I rarely use any more than 25% of that swap space, but this is
a general purpose multi-user system and so I really like to have at
least 50% more headroom for "emergencies".  If you can't easily monitor
your systems swap utilisation very closely (i.e. on 5 to 10-second
intervals at longest) during _all_ types of system activities then you
probably want at least 30%, and maybe as much as 50%-75% headroom over
observed "normal" usage too.  Most modern unix-like systems don't make
it very easy for users and administrators to control memory usage by
various applications and classes of applications and due to the many
years of experience developers have had with good virtual memory systems
we now have given them expectations about how easy it is for them to
simply gobble up huge amounts of memory space, and on a true general
purpose system many such applications these days don't run for very long
so swap utilisation can spike very easily (more easily the more active
users you have) and you might never know it unless you actually run
out.  On a more dedicated system it's often easier to measure actual
usage and calculate growth, but even then various system daemons, daily
processes, etc. that we all take for granted could spike usage at
certain times of day and unless you can measure on very small intervals
(i.e. smaller than the width of any potential spike), you'll never know
unless you actually run out of swap space.

There are a few placed in the various *BSD kernels now where peak
utilisation of various dynamic resources is now kept track of.  For
example FreeBSD now keeps track of some aspects of peak mbuf usage:

	$ netstat -m
	71/224/4096 mbufs in use (current/peak/max):
	        65 mbufs allocated to data
	        6 mbufs allocated to packet headers
	64/120/1024 mbuf clusters in use (current/peak/max)
	296 Kbytes allocated to network (9% of mb_map in use)
	0 requests for memory denied
	0 requests for memory delayed
	0 calls to protocol drain routines

Unfortunately no system I know of keeps track of peak swap usage, but
this has been on my todo list for NetBSD for a very long time now.


> Spreading it across devices might be a good idea too...

Spreading swap across devices is _always_ a really good idea, and that's
regardless of what OS you're running!  Even if 

There is one thing to consider though, especially with *BSD:  If you
care at all about diagnosing crashes you really must have at least as
much swap on your primary drive as you have RAM.  Either that or you
have to dedicate a dump partition that's as big as physical RAM and make
sure you've specified it carefully and exactly to your kernel.  I don't
know about SunOS-5, but *BSD cannot spread dumps across multiple
partitions.

Another thing to consider is that if you're using software RAID to try
to enhance the reliability and recoverabiltiy of your system then you
really have to do exactly the same for your swap partitions.  In fact
mirroring your swap partitions is probably even MUCH more important than
mirroring your root drive (assuming you have a relatively quiescent root
filesystem, as you should, at least with a correctly configured *BSD).

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods at ieee.org>;           <woods at robohack.ca>
Planix, Inc. <woods at planix.com>; VE3TCP; Secrets of the Weird <woods at weird.com>



More information about the geeks mailing list