About Top and Virtual Memory
A brief discussion of the 'top' UNIX command
Q: I have only the vaguest notion of the meaning of pageins and pageouts. If someone would clarify, I'd be most grateful. Just trying to get the most out of top, which I have running all the time.
Paging is about swapping stuff between real memory and hard disk (virtual memory). A pageout happens when you're out of RAM and something is moved off to disk to make room for something else. A pagein happens when that thing is needed again, and is moved from disk back into RAM. (A pagein can happen without a pageout -- for instance, when a chunk of code is loaded for the first time.)
Since hard drives are roughly a zillion times slower than RAM, high paging slows down your system. If you see consistently high (increasing numbers over time) paging in top (usually accompanied by frequent hard drive chattering), you may be a good candidate for adding RAM to your computer to speed it up by reducing paging.
You can have ~tons~ of RAM and still have paging. My Mac has 896 MB (a strange number: 128+256+512 :), and top indicates only 10.6 M free and 213 pageouts (since I restarted about half an hour ago). It's hardly memory starved... the system is just using that RAM for things such as caching until it's needed for something else. (At the time of this writing, I'm burning a CD in iTunes, and it appears to have cached the entire CD into RAM. (A good illustration of using available memory for disk caching!)
Don't let paging alone guide you to this. Also just pay attention to your general user experience. If you're hearing constant drive chattering (sometimes called thrashing!), this may indicate your paging is getting active -- but if you don't notice any slowness during the chattering, then adding memory may not make a very noticable difference.
interpretation
Q: ...paging numbers tend to get really high only when I've been running for two days or more without rebooting.
The paging numbers go up from zero. You can invoke 'top -d' to start counting from "the previous sample" (more or less from 0). 'top -e' gives a really different view of the same data which make pageins and faults really obvious. Consult the man page ('man top') and play -- you can't hurt anything with top, it's only a monitor.
Memory allocated but not in use
On Monday, July 30, 2001, at 02:41 AM, Eugene Lee wrote:
On Mon, Jul 30, 2001 at 08:35:41AM +0200, Michael Moss wrote:
:
: I have noticed in top, that there is quite a lot of memory that is allocated
: but not in use. As a result, when I open Classic, I only have 35 megs left
: out of 256. Is there any way to free up the unactive but allocated RAM?
No, and there's no point to.
To try to clarify Eugene's statement, you wouldn't want to if you could. OS X, like most unixes, loads code into RAM to execute them, or data to do things with. When that code or data is done, it leaves those "pages" of code/data in memory in case they are needed again. If they are, they are executed/used in place instead of being loaded from disk -- a very, very fast form of virtual memory. When the memory those pages are using is needed for something else, the Mach kernel throws them away and replaces them with code (or data) fetched from disk. The time required to discard them is effectively zero -- they are just overwritten with new code or data -- so the cost of this is low and the benefit is very high.
The more memory you have, the more benefit. Drop in another 256 meg and you'll see your paging drop to nearly zero -- everything tends to get kept because it rarely needs to be discarded. On my 768 meg work Mac, even loading Classic and Photoshop with a generous 300 meg of memory allocated to it ~still~ doesn't cause the machine to "page to disk" (unix-speak for resort to virtual memory).
downwardspiral.net © 2001–2007 robert mohns
|