Why use swap when there is RAM free?

Smoot Carl-Mitchell smoot at tic.com
Fri Aug 14 17:50:26 UTC 2009


On Fri, 2009-08-14 at 13:13 -0400, Rashkae wrote:

> Indeed, the linux kernel will proactively write dirty pages out to swap
> before it needs to free the ram for this very purpose, to have a pool of
> ram that can be evicted and used without having write to swap at the
> same time as you're trying to use more memory (the ultimate performance
> killer.)

Are you sure your not talking about the disk cache which will write
through memory pages to disk files periodically to prevent file
corruption?  This is cached memory in "top" and some of the other tools
to display memory statistics.  These pages are never written to swap.
Also read only executable code pages are not written to swap, since the
backing store is the file where the executable resides.

It is amusing to watch the cache grow as intensive disk I/O takes place.
If you want to see a graph of this take a look at
http://ns1.tic.com/~smoot/RRD and look at the memory utilization graph.
This machine is a server with 1GiB of memory.  The spikes in the cached
memory usage are where an I/O intensive process kicks off. In this case
it is my nearline backups using rsync.  You will notice the memory
utilization stays near 100% of the total memory available. This is by
design.  There is no reason to shrink the cached pages, since they are
effectively free if needed by other processes. The cache steals pages
from running processes to grow its size to make the I/O more efficient.
When I/O drops off, the cache shrinks as other processes demand more
memory and steal pages from the cache.

-- 
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
smoot at tic.com
+1 480 922 7313
cell: +1 602 421 9005




More information about the ubuntu-users mailing list