From owner-freebsd-stable@FreeBSD.ORG Mon Mar 6 23:16:00 2006 Return-Path: X-Original-To: stable@freebsd.org Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9DFED16A420; Mon, 6 Mar 2006 23:16:00 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id B94B643D48; Mon, 6 Mar 2006 23:15:59 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.3) with ESMTP id k26NFvXP065205; Tue, 7 Mar 2006 02:15:57 +0300 (MSK) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.3/Submit) id k26NFuXV065204; Tue, 7 Mar 2006 02:15:56 +0300 (MSK) (envelope-from yar) Date: Tue, 7 Mar 2006 02:15:56 +0300 From: Yar Tikhiy To: Nick Barnes Message-ID: <20060306231556.GB64952@comp.chem.msu.su> References: <44077091.3060604@freebsd.org> <80813.1141343429@thrush.ravenbrook.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <80813.1141343429@thrush.ravenbrook.com> User-Agent: Mutt/1.5.9i Cc: stable@freebsd.org Subject: Re: Failing to understand 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, 06 Mar 2006 23:16:00 -0000 On Thu, Mar 02, 2006 at 11:50:29PM +0000, Nick Barnes wrote: > At 2006-03-02 22:24:17+0000, Nik Clayton writes: > > I'm failing to understand how getrusage() works, which is a bit perplexing, > > because it doesn't seem like it would be terribly complicated. > > ru_maxrss is the maximum resident set size, not the heap size. > malloc(big) doesn't grow the resident set. Touching the memory you > have allocated will grow the resident set. Try this: > > getrusage(RUSAGE_SELF, &ru); > printf("%lu\n", ru.ru_maxrss); > p = malloc(SIZE); > assert(p) > getrusage(RUSAGE_SELF, &ru); > printf("%lu\n", ru.ru_maxrss); > for (i=0; i p[i] = 0; > } > getrusage(RUSAGE_SELF, &ru); > printf("%lu\n", ru.ru_maxrss); Well, there was a call to memset() in the original Nik's program while your code just does the same by itself. Personally, I'd like to say a "me too". /me too fails to see why in a quiet, idle system ru_maxrss is very unpredictable over numerous runs of the test program, both before and after the malloc+memset. Filling the memory with a non-zero value doesn't matter. Is it the Heizenberg daemon at work? :-) -- Yar