Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Mar 2006 23:50:29 +0000
From:      Nick Barnes <Nick.Barnes@pobox.com>
To:        Nik Clayton <nik@freebsd.org>
Cc:        stable@freebsd.org
Subject:   Re: Failing to understand getrusage() 
Message-ID:  <80813.1141343429@thrush.ravenbrook.com>
In-Reply-To: <44077091.3060604@freebsd.org>  from Nik Clayton <nik@freebsd.org>  of "Thu, 02 Mar 2006 22:24:17 %2B0000"

next in thread | previous in thread | raw e-mail | index | archive | help
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<SIZE; ++i) {
                p[i] = 0;
        }
        getrusage(RUSAGE_SELF, &ru);
        printf("%lu\n", ru.ru_maxrss);

Nick B



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?80813.1141343429>