Memory Accounting in Proc.h

Andrey Simonenko simon at comsys.ntu-kpi.kiev.ua
Fri Feb 18 08:40:43 PST 2005


On Fri, Feb 18, 2005 at 01:30:41AM -0800, Ashwin Chandra wrote:

> I read up on getrusage which says that ru_idrss and ru_isrss are measured
> in kilobytes * the number of clock ticks. So I wanted to retrieve the
> actual value in just KB by using a timeval struct that gets the user
> and system ticks and takes the structure fields and divides by this to
> get Kb. (similar to how it is done in kern_acct.c).

ru_utime and ru_stime are not measured in ticks, they are measured
in sec and usec.  getrusage() converts ticks to sec and usec by calcru().

> How can I accurately keep tabs of current memory usage per process?

I don't believe that ru_idrss (which accumulates vm_dsize) can be used
for true accounting of memory used by a process.  For example memory
can be mmap'ed, or not all pages can be used by a process even during
all of its lifetime.  Currently on my system there is one process
with vm_dsize equal to 200M, but it always uses only 6M for private
data and never touches the rest of its 194M.

The same can be said for ru_isrss (which accumulates vm_ssize),
but this value is more accurate.

A better way is to walk through vm_map_entries and count number
of pages, number of resident pages, etc... like procfs does.


More information about the freebsd-hackers mailing list