Memory Accounting in Proc.h

Ashwin Chandra ashcs at ucla.edu
Fri Feb 18 01:30:27 PST 2005


I am trying to get the fields ru_idrss, and ru_isrss to see the the current stack and data sizes for each process thats running in user space. 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). Upon doing this, the memory printouts seem to be inflated or not workign very well. For example I wrote a program as follows:

main()
{
int a[1000000];
while(1) {}
}


This initializes 4Mb of space on the stack. However when I print out the memory portion (Data +stack)/4 (since ru_irss and ru_drss are both multipled by PAGESIZE/1024, i get the value as around 173,000. If i take out the int delcaration and just have a while loop I still get around the same number (a little less). Do you know why this is?
How can I accurately keep tabs of current memory usage per process?

Ash


More information about the freebsd-hackers mailing list