[ale] top and SWAP

Brian Pitts brian at polibyte.com
Fri Sep 7 12:06:47 EDT 2007


Brian Pitts wrote:
> JK wrote:
>> John Wells wrote:
>>
>>> Guys,
>>>
>>> Would like some help in clarifying the SWAP column under top
>>
>> I believe (based on knowledge of the 2.4 series kernels) that
>> this reflects the amount of virtual memory owned by the process
>> whose backing store is the swap partition.  However, just because
>> a memory region is backed by swap does not mean it will ever
>> actually be *written out* to disk.  The "Used" number is the
>> amount of swap space actually in use on the disk.  If a swapped
>> region is never actually written to (a situation that is quite
>> common), it will never be physically present either in RAM or
>> on disk (it's *really* "virtual").  This is because swap is only
>> used to back anonymous (malloc()'d) memory, which is assumed to
>> be 0 if never written to. There's no reason to ever allocate
>> pages for 600MB of zeros; you only need real RAM or swap if the
>> process writes data to a page.
> 
> 
> I think this is almost right. A malloc will increase the size of the 
> virtual image, but not the resident size. Perhaps top calculates SWAP as 
> VIRT - RES? 

[snip]

There doesn't seem to be any information available to procps utilities 
like top about an individual processes swap usage. According to man 
proc,  nswap ("Number of pages swapped") in /proc/[number]/stat is not 
maintained. Here's a sample of the data for firefox on my system:

from top:
VIRT 188
RES 88
SWAP 100
CODE 76
DATA 138

from /proc/[number]/status
VmPeak:   193644 kB
VmSize:   192740 kB
VmLck:         0 kB
VmHWM:     90628 kB
VmRSS:     90356 kB
VmData:   141564 kB
VmStk:        88 kB
VmExe:        76 kB
VmLib:     34048 kB
VmPTE:       160 kB

from /proc/[number]/statm:
48185 22589 7525 19 0 35413 0

/proc/[number]/statm
               Provides information about memory status in pages.  The 
columns are:
                size       total program size
                resident   resident set size
                share      shared pages
                text       text (code)
                lib        library
                data       data/stack
                dt         dirty pages (unused in Linux 2.6)

-Brian



More information about the Ale mailing list