Memory Accounting in Proc.h

Dan Nelson dnelson at allantgroup.com
Fri Feb 18 08:56:06 PST 2005


In the last episode (Feb 18), Ashwin Chandra said:
> 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?

Possibly the compilter has optimized 'a' away since you neither read
from or write to it?  Try memset'ing it to zero and see if your numbers
change.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-hackers mailing list