Subject: Re: vm size wrongly reported
To: Lars Heidieker <lars@heidieker.de>
From: Andrew Brown <atatat@atatdot.net>
List: current-users
Date: 05/04/2003 10:59:02
>The vmsize in top and ps is calculated from these fields
>        segsz_t vm_tsize;       /* text size (pages) XXX */
>        segsz_t vm_dsize;       /* data size (pages) XXX */
>        segsz_t vm_ssize;       /* stack size (pages) */
>in struct vmspace wouldn't it be correct to report the size field from
>vm_map.

not entirely, since that (for example) includes all space added via
mmap(2) (shared libraries, etc).  you almost certainly *don't* want to
include shared libraries in the reported size since they're shared.

>Ok the vmsize would be quite big sometimes because of th stack space
>reservation.

the reservation isn't all counted.  the only thing counted here is
space that's actually been faulted into use.

    % pmap -D1
    proc->p_vmspace 0xcf8349c4 = { vm_refcnt = 1, vm_shm = 0x0,
	vm_rssize = 0, vm_swrss = 0, vm_tsize = 67, vm_dsize = 249,
	vm_ssize = 26, vm_taddr = 0x8048000, vm_daddr = 0x808b000,
	vm_maxsaddr = 0xbdc00000, vm_minsaddr = 0xbfc00000 }
    ...
    BDC00000  30720K                     [ stack ]
    BFA00000   1920K read/write/exec     [ stack ]
    BFBE0000     64K read/write/exec     [ stack ]
    BFBF0000     64K read/write/exec     [ stack ]

vm_ssize says i've used 26 pages out of the two megabyte reservation
for stack space.  again, if you used the size field from the vm_map,
you'd be counting all of that reservation, plus the empty space from
the top of the soft limit to the top of the hard limit (an additional
30 megabytes).  and the shared libraries.  etc.

perhaps what you want is something more intelligent that can walk
through the map, entry by entry, and count only:

    * the text segment
    * the data segment
    * stack segments that are backed by an amap (and only the number
      of used pages there)
    * any other entries backed by anon space up to the size of the
      allocation (or the number of pages?)

how do you want to count a one megabyte mapping of which i've only
used one page?

>And anyway whats up with merging the struct vmspace with struct vm_map?

processes need a vmspace.  the kernel only needs a vm_map.

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
werdna@squooshy.com       * "information is power -- share the wealth."