From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 18 16:56:06 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A4A8E16A4CE for ; Fri, 18 Feb 2005 16:56:06 +0000 (GMT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4383543D3F for ; Fri, 18 Feb 2005 16:56:06 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.1) id j1IGu5jc048875; Fri, 18 Feb 2005 10:56:05 -0600 (CST) (envelope-from dan) Date: Fri, 18 Feb 2005 10:56:05 -0600 From: Dan Nelson To: Ashwin Chandra Message-ID: <20050218165603.GA3752@dan.emsphone.com> References: <001001c5159c$8369aef0$abe243a4@ash> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001001c5159c$8369aef0$abe243a4@ash> X-OS: FreeBSD 5.3-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.8i cc: freebsd-hackers@freebsd.org Subject: Re: Memory Accounting in Proc.h X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Feb 2005 16:56:06 -0000 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@allantgroup.com