rusage and pthreads

Chuck Swiger cswiger at
Wed Jan 19 01:21:05 UTC 2011

On Jan 18, 2011, at 5:01 PM, Mark Terribile wrote:
> and continues further down
>        ru = &td->td_ru;
>        ru->ru_ixrss += pgtok(vm->vm_tsize);
>        ru->ru_idrss += pgtok(vm->vm_dsize);
>        ru->ru_isrss += pgtok(vm->vm_ssize);
> This looks to me like it's accumulating the data in per-thread counters.  What's more, it's consistent with what I'm seeing on the user side.  Note that this is 7.2; if 8.x behaves differently I'd like to know.

I wonder if all of the threads in a process might be pointing to the same struct rusage?

Nope, checking kern/kern_resource.c kern_getrusage(), there is a per-proc struct rusage_ext which gets the sum of the per-thread td->td_ru counters via rufetch() / ruxagg() you're right that the counters are now per-thread.

> Which would mean that a process that is occupying memory but doesn't happen to be running on that clock tick doesn't have its memory counted toward the total ... right?

That's right.


More information about the freebsd-questions mailing list