Clearing up Cache and Buffer

Kyle Rose krose at theory.lcs.mit.edu
Sat Apr 24 10:37:28 EDT 1999


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> My XOSView is showing 55M out of 64M RAM as being used. 2/3 of this
> is BUFF/CACHE memory. Earlier, I was running quite a few xterms.
> I shutdown X Windows, logged as root. Now in X Windows, XOSView still
> show 55M RAM used with the same level of BUFF/CACHE occupied. I only
> have 4 windows open.

One thing you want to be aware of is that Linux uses a copy-on-write
virtual memory policy; this means that when a process forks, the
memory is not copied immediately; rather, when a page is written to by 
either the parent or child, that particular page is copied.

Additionally, Linux executables are "demand-paged" and share code
memory.  The first means that code is loaded off the disk only when it
is needed; the entire executable does not need to be loaded if only a
small portion of it is used.  The second means that when two processes
using the same code are loaded, they do not use additional code
memory, since code in Linux is (almost) always read-only.

The whole point of this is that Linux executables use less memory than 
you'd think.  Unless you have a particularly large scrollback buffer
in your xterms, having twenty loaded will not use significantly more
memory than having one loaded.

> How do I find out what are the memory occupied by dead or exited
> processes? Is there an administrative tool to clean up the memory from
> dead processes?

For the most part, Linux will take care of this.  <SWIPE>Unlike
Windows, Linux has proper and reliable memory management.</SWIPE> Each
process in Linux is associated with its own virtual memory space;
whenever a process exits or is KILLed, the kernel frees all the memory
associated with that process.  As the page tables are managed by the
kernel and cannot be touched by unpriveleged user programs, only an
error in the kernel memory management code can cause kernel-level
memory leaks.

Occasionally, an X program will not exit correctly; Netscape does this 
to me all the time, as does esd.  If you want to kill a process that
should have died but didn't, just type "kill -KILL <pid>", where you
can find <pid> by using the ps program.  Your memory will return, good 
as new.

You should also be aware that you will hardly ever have few "used"
buffers; free memory is always allocated to the disk cache when
needed, because unused memory doesn't do anyone any good.  Rest
assured, Linux will flush writeback caches and deallocate some read
cache space if you need it.

To be fair, the problem with Windows' memory management isn't that the 
kernel manages memory incorrectly; rather, too many prograems are
priveleged, and they try to perform their own memory management
tricks.  This is bad news.

Kyle


- -- 
Kyle R. Rose                      "They can try to bind our arms,
Laboratory for Computer Science    But they cannot chain our minds
MIT NE43-309, 617-253-5883             or hearts..."
http://web.mit.edu/krr/www/                           Stratovarius
krose at theory.lcs.mit.edu                              Forever Free
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v0.9.5 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE3Idcm66jzSko6g9wRAjGOAKCTrZQ+ACK3sSn2cFc+zkAfC8QoHQCg6088
0GY4gBJdYm9RXf9EM2D/MJE=
=ELGg
-----END PGP SIGNATURE-----
-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).



More information about the Discuss mailing list