All,

I'm a bit confused on the difference between SIZE and RES in the
output of top(1) (the same goes for VSZ vs RSS in ps(1) output). The
manpage says :

SIZE    The total size of the process (the text, data, and stack
        segments).

RES     The current amount of resident memory.

Reading the page I'd think they should be equal; I'd say the total
size of the process should equal the amount of resident memory. This
is of course completely wrong (there's two fields for a reason), looking
at a semi-random pair of processes on a system I have running here, I
have one process with a SIZE of 696K and a RES of 19M (SIZE < RES) and
also another one with a SIZE of 176K and a RES of 4K (SIZE > RES).

I figured I'd check the code for more enlightenment. In
/usr/src/usr.bin/top/machine.c I see :

            format_k(pagetok(PROCSIZE(pp))),
            format_k(pagetok(pp->p_vm_rssize)),

PROCSIZE is #defined as the sum of (pp)->p_vm_[tds]size, but I can not
find how these sizes relate to p_vm_rssize. I eventually end up in
sys/sysctl.h where the kinfo_proc2 structure is defined. It says :

        int32_t p_vm_rssize;            /* SEGSZ_T: current resident set size 
in pages */
        int32_t p_vm_tsize;             /* SEGSZ_T: text size (pages) */
        int32_t p_vm_dsize;             /* SEGSZ_T: data size (pages) */
        int32_t p_vm_ssize;             /* SEGSZ_T: stack size (pages) */

This, unfortunately, does not clear things up for me, I'd still read
this to mean that rssize = tsize + dsize + ssize. How come SIZE can be
larger or smaller than RES ? Is there any documentation on this ?

The only thing I can think of is that RES does not take swapped out
memory into account ("resident" as in "active and currently loaded in
RAM"), but in that case SIZE >= RES, never SIZE < RES. And then I also
see SIZE > RES on machines that have never touched swapped since boot,
so that (partially) rules out swap as an answer. Is this perhaps
related to dynamic libraries which are shared between processes and
thus not counted in SIZE but are part of RES (or vice versa) ?
Unlikely to be a good/complete answer, static binaries also have
different values for SIZE and RES.

Anyway, I should probably stop making a fool out of myself by making
any more pointless guesses. Does anyone have a cluebat available for
me ?

Thanks,

Paul 'WEiRD' de Weerd

-- 
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/                 

Reply via email to