Subject: Re: Swap used for no reason?
To: Jeremy C. Reed <reed@reedmedia.net>
From: Chuck Swiger <cswiger@mac.com>
List: netbsd-help
Date: 01/07/2006 20:58:44
Jeremy C. Reed wrote:
[ ... ]
> I followed various ideas and a webpage for sysctls for tuning virtual 
> memory several times, but never got my old 128MB system to behave better. 
> I asked about this before.
> 
> How do you stop swap from being used (other than not having swap)?

The system has a daemon process (often called pager or paged or similar), which 
attempts to move pages of memory which have not been recently used out of the 
active set to swap, so that more memory is available for tasks which are 
actually active.  The system benefits by copying out inactive pages to swap, 
because it does not overwrite such pages in RAM until it needs to: pages being 
moved to the free list after being swapped out, can be reactivated before they 
get used by something else.

For example, well-written programs used to go to some trouble (cf tsort, lorder) 
to seperate out initialization code from the rest of the active text section, to 
encourage and facilitate the system to swap out unneeded pages that will never 
be needed once the program has started.

You can prevent the system from paging out sections of memory via the mlock() 
call; also see madvise(..., MADV_NOSYNC).

-- 
-Chuck