Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Memory 100% used. Is that a Bad Thing(tm)?



>>>>> "Jean-Christian" == Jean-Christian Imbeault <jean_christian@example.com> writes:

    Jean-Christian> I have 512M of RAM and top shows that it is all
    Jean-Christian> being used. But almost no swap space is being used
    Jean-Christian> ...

    Jean-Christian> Should I get more RAM

If you are using no swap and the machine is in "stable" state (ie, has
been running for quite a while), then you have far more memory than
you need for this application, even to run it efficiently.

    Jean-Christian> or is it normal for Linux to use all the RAM it
    Jean-Christian> can get?

It's normal.  The memory allocation strategy used by virtual memory
managers is to keep as much data as possible in memory once it has
been read, as well as an in-memory directory of what's there.  This
means that on a cache hit, you never go to disk.  With near certainty,
the page, whether static or dynamic, that http://www.j-c.net/ grabs
off disk only gets read once per boot or change.  I'm not sure what
the algorithm used is, but "discard LRU" (least-recently used) is a
simple example.

One implementation is to keep the cache directory entries in a linked
list.  So each time you read a new page into unused memory, you add a
new cache entry to the tail of the list.  When you read a cached page,
you unlink the directory entry and move it to tail.  This continues
until memory is full.

At that point, you have no unused memory.  If you need to read a new
page, you first bump the directory entry for the head off the list,
deallocate that directory entry, and mark the memory allocated to the
page as unused.  Now you're in the same situation as above.

Note what happens if you access a page already in the cache.  It's the
same as if you had plenty of unused memory!

Swap makes things more complicated.  But the thing to remember is that
accessing a swapped page is much less expensive (one disk read) than
accessing a page from a file system (multiple disk reads in many
cases), but much more expensive than accessing the RAM cache.

I have no idea what the algorithm for deciding whether to fill swap or
not is, but apparently either you only ever access less than 512MiB of
data, so it all fits in memory, or the VM has decided in its infinite
(see kernel-activists for detailed discussion of whether infinite is a
terribly big or terribly small amount :) wisdom that it's more
expensive to swap all the time than to access the file system
occasionally, so nothing ever accumulates in swap.

Either way, it seems there's little point in you getting more memory.

-- 
Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
 My nostalgia for Icon makes me forget about any of the bad things.  I don't
have much nostalgia for Perl, so its faults I remember.  Scott Gilbert c.l.py


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links