From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 18 16:40:42 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 E538316A4CE for ; Fri, 18 Feb 2005 16:40:42 +0000 (GMT) Received: from comsys.ntu-kpi.kiev.ua (comsys.ntu-kpi.kiev.ua [195.245.194.142]) by mx1.FreeBSD.org (Postfix) with ESMTP id 381AF43D41 for ; Fri, 18 Feb 2005 16:40:37 +0000 (GMT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from pm514-9.comsys.ntu-kpi.kiev.ua (pm514-9.comsys.ntu-kpi.kiev.ua [10.18.54.109]) (authenticated bits=0)j1IGhJcP053172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 18 Feb 2005 18:43:20 +0200 (EET) Received: by pm514-9.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1000) id F15DF80; Fri, 18 Feb 2005 18:40:22 +0200 (EET) Date: Fri, 18 Feb 2005 18:40:22 +0200 From: Andrey Simonenko To: Ashwin Chandra Message-ID: <20050218164022.GA405@pm514-9.comsys.ntu-kpi.kiev.ua> 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> User-Agent: Mutt/1.4.2.1i X-Spam-Status: No, score=-4.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.0.1 X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on comsys.ntu-kpi.kiev.ua X-Virus-Scanned: ClamAV 0.82/707/Thu Feb 17 00:00:07 2005 on comsys.ntu-kpi.kiev.ua X-Virus-Status: Clean 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:40:43 -0000 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.