get ram usage using getrusage()

Claus Guttesen kometen at gmail.com
Mon Dec 20 20:02:57 UTC 2010


> The "SIZE" column of top(1) is the same as the "VSZ" column
> of ps(1):  It displays the virtual process size.  Basically
> this is the sum of all VM mappings that are assigned to the
> process.  It has _nothing_ to do with the RAM usage.
>
> Somewhat more useful for your purpose is the resident set
> size ("RES" in top, "RSS" in ps).  This is the amount of
> memory actually in use.  But this also includes files that
> were mmap()ed, including libraries shared between many
> processes.  I'm not sure this is what you want.  Another
> problem is that the resident set size does NOT include
> pages in swap.  So, if your process is swapped completely,
> the RSS is zero, as you can see here:
>
>  PID USERNAME THR PRI NICE  SIZE RES STATE TIME   WCPU COMMAND
> 14388 olli       1   5    0 3864K  0K ttyin 0:00  0.00% <zsh>

Thank you (vielen dank :-) ) for your explanation.

> If you free an object with the free() function, the pages
> are not necessarily unmapped immediately.  This depends on
> the malloc implementation and configuration.  Also, even
> if it is unmapped, the rusage statistics are not updated
> immediately (this depends on the statclock, see ``sysctl
> kern.clockrate'').
>
> I think that applications should better track their memory
> usage themselves, so it is portable and independent of
> implementation details of the VM system and malloc library.
> That's what most applications do, for example squid.

I get a clearer picture (had to read your reply a couple of times) but
I'm on my way.

-- 
regards
Claus

When lenity and cruelty play for a kingdom,
the gentler gamester is the soonest winner.

Shakespeare

twitter.com/kometen


More information about the freebsd-stable mailing list