From owner-freebsd-stable@FreeBSD.ORG Mon Dec 20 08:09:18 2010 Return-Path: Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EB9E61065698 for ; Mon, 20 Dec 2010 08:09:18 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 6B8658FC1D for ; Mon, 20 Dec 2010 08:09:18 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id oBK890kc015324; Mon, 20 Dec 2010 09:09:16 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id oBK890AJ015323; Mon, 20 Dec 2010 09:09:00 +0100 (CET) (envelope-from olli) Date: Mon, 20 Dec 2010 09:09:00 +0100 (CET) Message-Id: <201012200809.oBK890AJ015323@lurza.secnetix.de> From: Oliver Fromme To: freebsd-stable@FreeBSD.ORG, kometen@gmail.com In-Reply-To: X-Newsgroups: list.freebsd-stable User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.5 (lurza.secnetix.de [127.0.0.1]); Mon, 20 Dec 2010 09:09:16 +0100 (CET) Cc: Subject: Re: get ram usage using getrusage() X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-stable@FreeBSD.ORG, kometen@gmail.com List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Dec 2010 08:09:19 -0000 Claus Guttesen wrote: > I'm trying to read how much ram an app is using reading Could you phrase that question more precisely? Note that "ram" and "memory" mean different things. Are you interested in the VM mapped to the process? Or do you want to know the amount of physical RAM only? Do you want to include pages that are currently paged to swap? Do you want to include shared pages, or only pages assigned exclusively to your process? Do you want to include memory that was free()ed but is still mapped to your process? And so on ... It might be helpful to know *WHY* you are interested in the app's RAM usage, in order to be able to give the most appropriate advice. > http://unix.derkeiler.com/Mailing-Lists/FreeBSD/stable/2006-03/msg00246.html > from ru.ru_maxrss. While ru.ru_maxrss gives me used accurate ram-usage > when memory increases it doesn't immediately count down when memory is > released. What do you mean by "released"? If you mean free(), that doesn't necessarily unmap pages from the process. I think that the current malloc() implementation uses madvise() with MADV_FREE (but I'm not 100% sure). But this is an implementation detail that applications should not care about. > So I tried to get a more accurate reading using this using > /usr/src/sys/kern/kern_clock.c as example: > > struct thread *td; > td = curthread; > p = td->td_proc; > vm = p->p_vmspace; > rss = pgtok(vmspace_resident_count(vm)); > > Curthread is not defined, I searched google but can't find any references. That's a piece of kernel source code. It won't work in user space. > But is this the proper way to get an apps memory usage? I think asking for an app's "memory usage" is not proper in the first place. :-) Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "FreeBSD is Yoda, Linux is Luke Skywalker" -- Daniel C. Sobral