From owner-freebsd-stable@FreeBSD.ORG Mon Dec 20 09:29:00 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 763381065675 for ; Mon, 20 Dec 2010 09:29:00 +0000 (UTC) (envelope-from kometen@gmail.com) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 27DFF8FC21 for ; Mon, 20 Dec 2010 09:28:59 +0000 (UTC) Received: by qwj9 with SMTP id 9so2407358qwj.13 for ; Mon, 20 Dec 2010 01:28:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=FkmuuPX6Fj8Uaup7bP22ujmNJDGfQ7275RAEoSP7yfk=; b=YmvurEKDpsQKhd9P/YeYP0HtcAx5sY37BTdtT6efoTJ5HBpM2HBIFQBIjGm7dJnXkI QUNBoZOlUkGGSiqlooLvTGDazePGpqlzmfNvX1ZITxnA6t3sT9llfN7TpTt++KXELUFM ade6yc7LjwXk9O7nIKaVvhxRyrm8lAfKAMmPE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=qsSSjBo5clJ4Zjeo767yjgrPgfxwVsPa9i4eA5EU9oRg8N026jufFiHvrAWy40SOiS Xt0Yp0gblvm1bT3NWxoDMXT7pjXUhfBtUWhILCHMphpW9NyYyq7C+PVSbn2a4CBPBHkJ TmOfUUgMyRQzcFZm/rRDW1ZQOpiRyd6JEZmSc= MIME-Version: 1.0 Received: by 10.229.84.137 with SMTP id j9mr3637754qcl.214.1292837337573; Mon, 20 Dec 2010 01:28:57 -0800 (PST) Received: by 10.229.95.205 with HTTP; Mon, 20 Dec 2010 01:28:57 -0800 (PST) In-Reply-To: <201012200809.oBK890AJ015323@lurza.secnetix.de> References: <201012200809.oBK890AJ015323@lurza.secnetix.de> Date: Mon, 20 Dec 2010 10:28:57 +0100 Message-ID: From: Claus Guttesen To: freebsd-stable@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: get ram usage using getrusage() X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list 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 09:29:00 -0000 >=A0> I'm trying to read how much ram an app is using reading > > Could you phrase that question more precisely? > 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. I'm testing the redis key-value-store with the (upcoming 2.2) maxmemory directive and redis - at least on FreeBSD - seems to report less ram used than what is shown in top (SIZE column). ru.ru_maxrss is more accurate at least when redis grows. Redis is useful with an expire in the key (setex) in my case where I want to store as much as possible and retain used key and have redis delete unused keys (LRU) In freeMemoryIfNeeded() redis deletes keys until allocated memory < maxmemory. I used ru.ru_maxrss for testing allocated memory but I ended up deleting all keys since ru.ru_maxrss is not counting down "fast enough", probably for quite reasonable reasons. But not what I wanted. :-) When I used redis zmalloc_used_memory() the server starts swapping. >=A0> struct thread *td; >=A0> td =3D curthread; >=A0> p =3D td->td_proc; >=A0> vm =3D p->p_vmspace; >=A0> rss =3D pgtok(vmspace_resident_count(vm)); > > That's a piece of kernel source code. =A0It won't work in > user space. Saw #ifdef _KERNEL in older versions of sys/pcpu.h that explicitly told it was kernel-related code (http://fxr.watson.org/fxr/source/sys/pcpu.h?v=3DFREEBSD70) but not on 8-stable. > I think asking for an app's "memory usage" is not proper in > the first place. =A0:-) Maybe the reason userland apps have their own accounting system? Can you elaborate? :-) --=20 regards Claus When lenity and cruelty play for a kingdom, the gentler gamester is the soonest winner. Shakespeare twitter.com/kometen