Measuring RSS on Mac when MADV_FREE is used

Justin Lebar jlebar at mozilla.com
Tue Oct 11 07:57:39 PDT 2011


At Mozilla, we recently ported our jemalloc fork to MacOS.  It works
great, except we've noticed that our RSS measurements are now
basically useless, because memory freed with madvise(MADV_FREE) is
counted against our process's RSS until the system starts running low
on memory and steals those pages away from us.

As far as I can tell, upstream jemalloc has the same behavior.

In contrast, MADV_DONTNEED on Linux releases memory (almost) immediately.

I don't think what MacOS is doing here is so unreasonable; the problem
isn't so much that it's holding onto this memory, but rather that I
now can't meaningfully measure my process's RSS via the operating
system.  (The program can compute this value, of course, by measuring
how much memory it's MADV_FREE'd.)

Do you guys know of any way I can force MacOS to drop my MADV_FREE'd
pages, short of making a large allocation in another process (which
might have other side-effects, like paging out things I want to keep
in memory)?  Or is there a way to directly measure how many
non-MADV_FREE'd pages my process is using?  I'm pretty stumped.

Regards,
-Justin



More information about the jemalloc-discuss mailing list