Beginning on October 25th, 2016, Persona will no longer be an option for authentication on BMO. For more details see Persona Deprecated.
Last Comment Bug 681183 - Make jemalloc_stats.committed meaningful on *nix (where MALLOC_DECOMMIT is not defined)
: Make jemalloc_stats.committed meaningful on *nix (where MALLOC_DECOMMIT is no...
Product: Core
Classification: Components
Component: Memory Allocator (show other bugs)
: unspecified
: x86_64 Linux
: -- normal (vote)
: mozilla10
Assigned To: Justin Lebar (not reading bugmail)
: Mike Hommey [:glandium]
Depends on: 683597
Blocks: 692963
  Show dependency treegraph
Reported: 2011-08-22 21:15 PDT by Justin Lebar (not reading bugmail)
Modified: 2011-10-11 02:34 PDT (History)
6 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

Patch v1 (13.29 KB, patch)
2011-10-07 13:36 PDT, Justin Lebar (not reading bugmail)
khuey: review+
Details | Diff | Splinter Review

Description Justin Lebar (not reading bugmail) 2011-08-22 21:15:30 PDT
With MALLOC_DECOMMIT defined, jemalloc will decommit memory it doesn't think it needs.  When DECOMMIT is not defined, jemalloc madvise(MADV_FREE / MADV_DONTNEED)'s memory it doesn't need.

AFAICT, a page is MADV_FREE'd iff it would be decommitted, were DECOMMIT defined.

For the purposes of jemalloc_stats.committed, a page is "committed" even after it's been MADV_FREE'd.  But OS issues aside (I understand this may not be the case on Mac), a MADV_FREE'd page should be quickly returned to the operating system.

So I propose modifying jemalloc to report a new field, call it, which is equal to jemalloc_stats.committed when DECOMMIT is defined, and, when DECOMMIT is not defined, is equal to what jemalloc_stats.committed would be if DECOMMIT were defined.  That is, it treats MADV_FREE'd memory as "not live".

I think this should be pretty simple to do, because the machinery is already there to support DECOMMIT. would allow us to measure how much of the live heap is fragmented.  Right now, we can only do this meaningfully on Windows.

Bug 674290 is an alternate way to get a similar result, assuming that jemalloc makes the vast majority of anonymous mappings.  But I think it would be good to measure this directly in jemalloc.

This work would of course be overwritten if and when we update to the new version of jemalloc.
Comment 1 Justin Lebar (not reading bugmail) 2011-10-07 10:14:53 PDT
This is important because it lets us compute how much fragmentation there is in jemalloc on *nix.

Currently, the only way I know of to compute the amount of wasted memory in jemalloc is to compute

 resident/anonymous - (heap-allocated + js-gc-heap).

This gives you the amount of resident memory that isn't due to live heap allocations or the js gc heap.  This value includes all of the heap fragmentation, but it may include other anonymous mappings.  We can't really tell right now.
Comment 2 Justin Lebar (not reading bugmail) 2011-10-07 13:36:41 PDT
Created attachment 565638 [details] [diff] [review]
Patch v1

Note the dependency on bug 683597.
Comment 3 Justin Lebar (not reading bugmail) 2011-10-07 13:37:46 PDT
I wonder if we can test this somehow, or if we need to resort to prayer.
Comment 4 Justin Lebar (not reading bugmail) 2011-10-10 12:13:25 PDT
Comment 5 Marco Bonardo [::mak] 2011-10-11 02:34:28 PDT

Note You need to log in before you can comment on or make changes to this bug.