Why use swap when there is RAM free?

Rashkae ubuntu at tigershaunt.com
Fri Aug 14 17:13:41 UTC 2009


Vincent Arnoux wrote:
> On Thu, Aug 13, 2009 at 16:00, Smoot Carl-Mitchell<smoot at tic.com> wrote:
>> It will when the swapped pages are needed again.  There is no reason to
>> do the I/O when it is not required.
> 
> OK, I had the impression it was smarter to put data back to RAM anyway
> as I will for sure need it at one point... Thanks for the
> explanations.
> 


It's not sure at all that the memory will be needed.

There used to be experimental Swap Pre-fetch kernels that do exactly
what you described, and while they could be demonstrated to give a
performance boost under some circumstances, so far, the difference
wasn't enough for the Kernel mainline managers to incorporate it.  Maybe
someone will resurrect the idea eventually.

However, there is one very important detail that so far none of
mentioned.  Even if the memory is read back from swap to Ram, either
on-demand or from pre-fetch mechanism, the memory will still stay in
swap.  Memory that exists both in Ram and swap (which is to say, the
pages have not been changed since they were first written to swap) is
called a clean page, and the benefit of a clean page is that the Ram can
at any time be evicted without first having to swap out.

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.)




More information about the ubuntu-users mailing list