D.W. D.W. - 1 year ago 124
C Question

Units of `ru_maxrss` on BSD?

returns a struct containing

long ru_maxrss; /* max resident set size */

What are the units of
, on BSD operating systems? Is this value in bytes, or in kilobytes? By "BSD", I mean FreeBSD, OpenBSD, but not Mac OS X / Darwin.

The FreeBSD man page and OpenBSD man page say the units are in kilobytes:

ru_maxrss the maximum resident set size utilized (in kilobytes).

However, I know that on Darwin / Mac OS X, the units are in bytes (even though online man pages claim otherwise), and I have also found some statements online that claim on BSD
is also returned in bytes (see e.g. here). Which is correct?

Answer Source

On FreeBSD it's in kilobytes, as evidenced by the source in kern_clock.c:

/* Update resource usage integrals and maximums. */
MPASS(p->p_vmspace != NULL);
vm = p->p_vmspace;
ru = &td->td_ru;
ru->ru_ixrss += pgtok(vm->vm_tsize) * cnt;
ru->ru_idrss += pgtok(vm->vm_dsize) * cnt;
ru->ru_isrss += pgtok(vm->vm_ssize) * cnt;
rss = pgtok(vmspace_resident_count(vm));
if (ru->ru_maxrss < rss)
    ru->ru_maxrss = rss;

pgtok() computes kb from page size.

But who would believe the kernel source? Lets run a program:

$ cat x.c
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>

int main(void)
    struct rusage r;

    if (getrusage( RUSAGE_SELF, &r) == 0) {
       printf ("ru_maxrss=%lu\n", (unsigned long)r.ru_maxrss);
    return 0;
$ ./a.out
$ ./a.out
$ ./a.out
$ ./a.out

These numbers aren't multiples of 1024, so can't be bytes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download