Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jun 1999 09:02:37 +0930
From:      Greg Lehey <grog@lemis.com>
To:        Mitch Collinsworth <mkc@Graphics.Cornell.EDU>
Cc:        Thomas David Rivers <rivers@dignus.com>, rfg@monkeys.com, questions@FreeBSD.ORG
Subject:   Swap usage (was: Desperate to shrink a partition)
Message-ID:  <19990618090237.M9893@freebie.lemis.com>
In-Reply-To: <199906172028.AA210841314@broccoli.graphics.cornell.edu>; from Mitch Collinsworth on Thu, Jun 17, 1999 at 04:28:33PM -0400
References:  <199906171950.PAA77238@lakes.dignus.com> <199906172028.AA210841314@broccoli.graphics.cornell.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday, 17 June 1999 at 16:28:33 -0400, Mitch Collinsworth wrote:
>
>> And - it may be a requirement that swap be as large as physical memory,
>> if not twice as large...
>
> On p. 62 of the Lehey book (2nd ed.) there is a lengthy discussion
> entitled "How much swap?"
>
> The last point says:
>
> "Even with lightly memory loads, the virtual memory system slowly pages
> out data in preparation for a possible sudden demand for memory.  This
> means that it can be mor responsive to such requests.  As a result, you
> should have at least as much swap as memory."

Right.  But that's a "should", not a "must".  Here's the complete
text:

It's  very  difficult  to  predict how much swap space you need.  The automatic
option gave us 42 MB.  In the manual example, we chose 32 MB.   Maybe  you  can
get by with 16 MB.  Maybe you'll need 512 MB.  How do you decide?

It's  almost impossible to know in advance what your system will require.  Here
are some considerations:

o Swap space is needed for all pages of virtual memory which contain data  that
  is  not locked in memory and which can't be recreated automatically.  This is
  the majority of virtual memory in the system.

o Some people use rules of thumb like ``2.5 times the size of physical  memory,
  or 64 MB, whichever is bigger''.  These rules work only by making assumptions
  about your workload.  If you're using more than 2.5 times as much swap  space
  as physical memory, performance will suffer.

o Known  memory  hogs  are X11 and the GNU C compiler (gcc).  If you use these,
  you will probably need more swap space.

o You can add  additional  swap  partitions  on  other  disks.   This  has  the
  additional  advantage of balancing the disk load if your machine swaps a lot.

o About the only ways to change the size of a swap partition are to add another
  partition  or  to  reinstall  the system, so if you're not sure, a little bit
  more won't do any harm, but too little can really be a problem.

o If your system panics, and memory dumping  is  enabled,  it  will  write  the
  contents  of  memory  to the swap partition.  This will obviously not work if
  your swap partition is smaller than main memory.  Under these  circumstances,
  the  system  refuses  to dump, but it's not impossible that a bug might cause
  the dump to write beyond the bounds of the swap partition,  probably  causing
  irreperable damage to your /usr partition.

o Even with light memory loads, the virtual memory system slowly pages out data
  in preparation for a possible sudden demand for memory.  This means  that  it
  can  be  more  responsive  to such requests.  As a result, you should have at
  least as much swap as memory.

A couple of examples might make this clearer:

1. I run X, StarOffice,  Netscape  and  a  whole  lot  of  other  memory-hungry
  applications  on  my  old 486 with 16 MB.  Sure, it's really slow, especially
  when changing from one application to another, but it works.   Since  there's
  not much memory, it uses a lot of swap.

  To  view  the  current  swap usage, use pstat.  Here's a typical view of this
  machine's swap space:

  $ pstat -s
  Device      1024-blocks     Used    Avail Capacity  Type
  /dev/sd0s1b      122880    65148    57668    53%    Interleaved


2. I run much more stuff on my Pentium with 96 MB of memory.  I've got lots  of
  swap space, but what I see is:

  $ pstat -s
  Device      1024-blocks     Used    Avail Capacity  Type
  /dev/wd0s1b       51200    14416    36720    28%    Interleaved
  /dev/sd0b         66036    14332    51640    22%    Interleaved
  /dev/sd2b        204800    14384   190352     7%    Interleaved
  Total            321844    43132   278712    13%

It's  not  so important that the Pentium is using less swap: it's using 0.67 of
its memory in swap, whereas the 486 is using 4 times its memory.   Look  at  it
from  a different point, and it makes more sense: swap makes up for the lack of
real memory, so the 486 is using a total of 80 MB of memory, and the Pentium is
using 140 MB.  In other words, there is a tendency to be able to say ``the more
main memory you have, the less swap you need''.

If, however, you look at it from the point of view of  acceptable  performance,
you  will hear things like ``you need at least one-third of your virtual memory
in real memory''.  That makes sense from a performance point of view,  assuming
all  processes  are  relatively  active.   And,  of course, it's another way of
saying ``take twice as much swap as real memory''.

In summary: be generous in allocating swap space.  In this example, we  have  a
tiny  disk,  so  we're  forced  to use a small swap partition.  If you have the
choice, use more.  If you really can't make up your mind, take 256 MB  of  swap
space.


> [Buy the book, it's loaded with useful stuff, even if you've been
> a sysadmin for decades.]

Thanks.

Greg
--
When replying to this message, please copy the original recipients.
For more information, see http://www.lemis.com/questions.html
See complete headers for address, home page and phone numbers
finger grog@lemis.com for PGP public key


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990618090237.M9893>