[ale] top and SWAP

JK jknapka at kneuro.net
Fri Sep 7 13:09:22 EDT 2007


John Wells wrote:
> ----- "JK" <jknapka at kneuro.net> wrote:
> 
>>True. But "swapped out" is a logical concept -- for a particular
>>virtual page to be "swapped out" just means that the page is
>>not physically present in RAM, and that *something* has to
>>be done to acquire the page if it is accessed.  It does not
>>necessarily mean that a physical page has been written out
>>to a swap partition.
>>
>>(This is just a fact about the Linux VM system, not a
>>universal truth about swapping.)
> 
> 
> But on your typical system, where can it go aside from RAM and swap partitions?

(1) Pages from shared files (shared libraries like libc,
and other files mapped into shared memory via mmap()) are
backed by the open file, so never need to be associated
with swap.

(2) Pages allocated anonymously via malloc() are satisfied
from a single global zero page. If the contents of such a
(virtual) page are ever changed, a new is physically allocated
and mapped to the appropriate virtual address within the
process's VM, and the change is made to the new page (so the
zero page always remains filled with zeros).  The new
page is assigned to a swap partition, but unless the
OS actually decides it needs to use the physical page
for something else, it won't actually be written to the
swap partition.

(3) Pages of child processes (spawned by fork()) are
physically shared with the parent process and need not
be allocated separately -- unless the child process
changes the contents of such a page, in which case a new
page is allocated as in case (2). (This is "copy-on-write".)

-- 
"What can be asserted without evidence can also be
dismissed without evidence." -- Christopher Hitchens



More information about the Ale mailing list