Why use swap when there is RAM free?
Steve Lamb
grey at dmiyu.org
Fri Aug 14 11:41:59 UTC 2009
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. Which is where this whole
thing was heading to. ;)
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. But that's just me surmising based on what I've learned via osmosis
over the years and not actually backed up by, you know, research, web pages or
even an ill-conceived link to a half-formed Wikipedia article. So take that
as you will. ;)
Needless to say that the kernel (developers) has reasons for what it
does; oft times to the bewilderment of those not elbow deep in its code. ;)
--
Steve C. Lamb | But who can decide what they dream
PGP Key: 1FC01004 | and dream I do
-------------------------------+---------------------------------------------
More information about the ubuntu-users
mailing list