Subject: Re: Swap used for no reason?
To: Jeremy C. Reed <reed@reedmedia.net>
From: Charles Swiger <cswiger@mac.com>
List: netbsd-help
Date: 01/09/2006 17:17:51
On Jan 9, 2006, at 4:31 PM, Jeremy C. Reed wrote:
>> Why do you care?  As soon as the programs that use those pages try
>> to access them, they will we read into memory.  Since that hasn't
>> happenned already, it may well not happen at all!
>
> I cared because I didn't think my swap should have been used in the  
> first
> place.
>
> And now I see that I have 38MB of swap used although my "buffers" is
> around 137MB (37MB cached executable pages and 99MB cached file  
> pages) and
> I have 1MB free real memory.
>
> (A few minutes ago, I had 8MB free real memory and still 137MB  
> buffers and
> 38MB used but my cached executable pages was around 30MB.

A system will normally page out some stuff to the swapfile, but that  
should stabilize relatively quickly.  If your swap usage continues to  
grow significantly without you running a lot of new processes, you  
may be running a program which is leaking memory.

> But if I understand Chuck's reply, some software is written to  
> encourage
> the swapping.
>
> Are there any benchmarks for this? When is it better to use hard  
> disk for
> swapping memory versus using real memory for caching hard disk?

Yes, it is possible to benchmark VM, but the practice of this is  
strewn with pitfalls; it's easy to measure something, then make a  
change which improves what you're measuring, only at a cost to the  
rest of the system performance.

Normally, a BSD system will only try to keep a few percent (generally  
1-5MB) of RAM as prezeroed pages to hand to processes faulting their  
BSS region, the rest will be used to cache stuff using a LRU-like  
algorithm called "second-chance replacement" or "the Unix clock-hand  
replacement" algorithm.  Writing a dirty page out to swap does not  
remove it from being a candidate for reclamation and being moved back  
from the free list to the active list, if that page turns out to be  
needed again before the kernel uses that memory for something else.

Matt Dillon wrote a good article here:

http://www.freebsd.org/doc/en_US.ISO8859-1/articles/vm-design/index.html

...which is mostly applicable to NetBSD.

-- 
-Chuck