Subject: Re: Swap sizes vs. physical memory.
To: David Brownlee <abs@anim.dreamworks.com>
From: Eduardo E. Horvath <eeh@one-o.com>
List: netbsd-help
Date: 09/09/1999 10:16:15
I don't want to get into which system is better, but at least the
descriptions should be accurate.

On Thu, 9 Sep 1999, David Brownlee wrote:

> 	That is correct - NetBSD does not preallocate swap space based on

First of all, it's not preallocation, it's reservation.  The swap space is
reserved for potential but not yet existant mappings.  

> 	programs' current data usage. In a preallocation model:
> 		virtual memory = min(physical memory,swap).

The amount of virtual does not change, it's always either:

		virtual memory = swap

or:

		virtual memory = physical memory + swap.

depending on the VM design.  Both NetBSD (which does not reserve) and
SunOS 5.x (a.k.a. Solaris) (which does reserve) use the latter formula.

> 
> 	In the NetBSD model:
> 		virtual memory = physical memory + swap.
> 
> 	This means you have more virtual memory available, but is it
> 	possible to malloc memory correctly and then fail when you come
> 	to use it.

This part is accurate.  

> 
> 	In either model a process can be killed when you run out of VM.

This is not.  In a VM implementation that uses swap reservation, ever VM
operation that could require additional backing pages in future needs to
reserve those pages first.  If there is not enough swap available for that
operation to reserve, the operation fails returning ENOMEM or EAGAIN,
preventing the system from ever getting into a situation where random
processes need to be killed.  

The tradeoffs are that with reservation you usually end up reserving large
amounts of swap space that may never be used, so you will hit the limit
sooner,  but the kernel will not need to do any cleanup work.  Without
reservation, you use all of your available swap space, but then the kernel
cannot recover cleanly and will need to start killing things which are as
likely not to be involved in the memory shortfall.

NetBSD currently does not reserve swap pages but allocates them as needed,
which can result in a situation where the kernel has committed itself to
providing more pages than are available in the system.

=========================================================================
Eduardo Horvath				eeh@one-o.com
	"I need to find a pithy new quote." -- me