Why use swap when there is RAM free?

Florian Diesch diesch at spamfence.net
Fri Aug 14 19:13:33 UTC 2009


Steve Lamb <grey at dmiyu.org> writes:

> Florian Diesch wrote:
>> Vincent Arnoux <vincent.arnoux at gmail.com> writes:
>>> 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... 
>
>> It's often smarter to put data that seems not to be used into the swap
>> to free up RAM.
>
>      It is often smarter to use free RAM for cache/buffers of more often used 
> data than to keep little used programs in memory.  


Or to swap out memory when the computer is idle, so you don't have to
when the computer is busy.


>      To explain in greater detail.  Imagine that you have some little used 
> program (ooohhhh, getty 2-6, just to name a few) that are just sitting there 
> taking up RAM.  During the course of your day you load up a ton of other 
> programs and lots and lots of data.  The programs + data exceeds your RAM (as 
> modified by swappiness, but that's another topic) so those programs are 
> swapped out.
>
>      Since you (or hardly any home user) will use getty 2-6 between now and 
> the heat death of the universe the kernel has a choice.  Swap those programs 
> in on the off chance you're going to use them or, since you haven't used them 
> in the past 30 days, figure you're not going to use them soon and leave them 
> be so the next time you use tons of RAM for programs + data it doesn't have to 
> spend the time to swap them back out of memory.  The kernel, as you have seen, 
> chooses the latter.
>
>      In fact I believe that the kernel will, if a program is not actively used 
> in x amount of time, swap out programs even if you don't hit your max on the 
> anticipation of you needing the free RAM sooner than you'll need to use those 
> programs.  

Yes., That's what is controlled by the
"swappiness", see <https://help.ubuntu.com/community/SwapFaq>

To see which programs use swap space start top, hit "f", "p" <Return>,
"O", "P" <Return>. The sum is usually bigger than the actually used swap
space as for each process all swap space it used is displayed, but some
is used by more than one process (like shared libs)


   Florian
-- 
<http://www.florian-diesch.de/>




More information about the ubuntu-users mailing list