[ale] Can someone help me understand memory usage?

Joseph A Knapka jknapka at earthlink.net
Thu Apr 25 23:19:36 EDT 2002


Chris Fowler wrote:
> 
> A friend just installed 384 megs of memory in his Linux box.  It is still
> swapping to disk.

Then either (a) he's using a kernel with broken VM
(2.4.<10), (b) the box is actually running code that
requires > 384MB of memory.
 
> Questions:
> 
> 1) What is cahced memory?

Cached memory is memory that has recently been mapped into
some process address space. The kernel keeps it in RAM,
rather than just freeing it, because chances are very
good that recently-used pages will be used again in
the near future, and when some process tries to map a
page it's way cheaper to find it in memory than to swap
it in from disk. When the kernel needs a "free" page, it
usually grabs a page off of the cache.

> 2) What would there be memory in cache and the box be using swap?

In older versions of the 2.4 VM system, the interaction
between the page cache and the swap mechanism was
seriously broken. It was possible for pages in the
cache to actually be in use by processes (IOW mapped
into process address spaces); under some conditions
the kernel would try to grab a free page off of the
cache and find that there actually weren't any
*free* pages on the cache (even though the cache
had lots of pages in it). The kernel would then
madly start to page stuff out to make free memory.
The 2.4.10 kernel, with Andrea Archangeli's VM
rewrite, pretty much solved that issue, as well
as some others.

> 3) Is there a such thing as free memory?

Yes, but it's pointless. The cost of swapping in
a page from disk is many thousands of times that
of locating a page in the page cache, so it makes
sense to optimize for the common case (the page
being faulted is one that was recently mapped),
and keep every page that's ever been used in
the page cache, and only throw them away when
you really need to bring something in from disk.

There does need to be some genuinely free memory
around for some purposes, but it's a tiny
amount, a few dozen pages typically.
 
Cheers,

-- Joe
  Using open-source software: free.
  Pissing Bill Gates off: priceless.

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list