Bug 898558 - Rework jemalloc_stats so it exposes how much memory is used for bookkeeping. r=glandium
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 29 Jul 2013 09:10:53 -0700
changeset 140420 905805f269ba4af34a7dc8096a61c56a36623ddf
parent 140419 a81349b61b4e2044f049572e57d727c5d434c727
child 140421 d4f1b39a85750b84a792920bcd4f4714cb574ed5
push id25030
push userryanvm@gmail.com
push dateTue, 30 Jul 2013 17:07:39 +0000
treeherdermozilla-central@129ce98f4cb2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs898558
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 898558 - Rework jemalloc_stats so it exposes how much memory is used for bookkeeping. r=glandium This patch also gets rid of the redundant "committed" entry, so now there's no confusion as to which entries overlap.
memory/mozjemalloc/jemalloc.c
memory/mozjemalloc/jemalloc_types.h
--- a/memory/mozjemalloc/jemalloc.c
+++ b/memory/mozjemalloc/jemalloc.c
@@ -6720,50 +6720,56 @@ jemalloc_stats_impl(jemalloc_stats_t *st
 	stats->large_max = arena_maxclass;
 	stats->chunksize = chunksize;
 	stats->dirty_max = opt_dirty_max;
 
 	/*
 	 * Gather current memory usage statistics.
 	 */
 	stats->mapped = 0;
-	stats->committed = 0;
 	stats->allocated = 0;
-	stats->dirty = 0;
+        stats->waste = 0;
+	stats->page_cache = 0;
+        stats->bookkeeping = 0;
 
 	/* Get huge mapped/allocated. */
 	malloc_mutex_lock(&huge_mtx);
 	stats->mapped += stats_chunks.curchunks * chunksize;
-	stats->committed += huge_allocated;
 	stats->allocated += huge_allocated;
 	malloc_mutex_unlock(&huge_mtx);
 
 	/* Get base mapped. */
 	malloc_mutex_lock(&base_mtx);
 	stats->mapped += base_mapped;
 	assert(base_committed <= base_mapped);
-	stats->committed += base_committed;
+	stats->bookkeeping += base_committed;
 	malloc_mutex_unlock(&base_mtx);
 
 	/* Iterate over arenas and their chunks. */
 	for (i = 0; i < narenas; i++) {
 		arena_t *arena = arenas[i];
 		if (arena != NULL) {
+                        size_t arena_allocated, arena_committed;
 			malloc_spin_lock(&arena->lock);
-			stats->allocated += arena->stats.allocated_small;
-			stats->allocated += arena->stats.allocated_large;
-			stats->committed += (arena->stats.committed <<
-			    pagesize_2pow);
-			stats->dirty += (arena->ndirty << pagesize_2pow);
+
+                        arena_allocated = arena->stats.allocated_small +
+                                          arena->stats.allocated_large;
+                        arena_committed = arena->stats.committed << pagesize_2pow;
+
+                        assert(arena_allocated <= arena_committed);
+
+			stats->allocated += arena_allocated;
+                        stats->waste += arena_committed - arena_allocated;
+			stats->page_cache += (arena->ndirty << pagesize_2pow);
 			malloc_spin_unlock(&arena->lock);
 		}
 	}
 
-	assert(stats->mapped >= stats->committed);
-	assert(stats->committed >= stats->allocated);
+	assert(stats->mapped >= stats->allocated + stats->waste +
+                                stats->page_cache + stats->bookkeeping);
 }
 
 #ifdef MALLOC_DOUBLE_PURGE
 
 /* Explicitly remove all of this chunk's MADV_FREE'd pages from memory. */
 static void
 hard_purge_chunk(arena_chunk_t *chunk)
 {
--- a/memory/mozjemalloc/jemalloc_types.h
+++ b/memory/mozjemalloc/jemalloc_types.h
@@ -67,18 +67,23 @@ typedef struct {
 	size_t	large_max;	/* Max sub-chunksize allocation size. */
 	size_t	chunksize;	/* Size of each virtual memory mapping. */
 	size_t	dirty_max;	/* Max dirty pages per arena. */
 
 	/*
 	 * Current memory usage statistics.
 	 */
 	size_t	mapped;		/* Bytes mapped (not necessarily committed). */
-	size_t	committed;	/* Bytes committed (readable/writable). */
-	size_t	allocated;	/* Bytes allocated (in use by application). */
-	size_t	dirty;		/* Bytes dirty (committed unused pages). */
+	size_t	allocated;	/* Bytes allocated (committed, in use by application). */
+        size_t  waste;          /* Bytes committed, not in use by the
+                                   application, and not intentionally left
+                                   unused (i.e., not dirty). */
+        size_t	page_cache;	/* Committed, unused pages kept around as a
+                                   cache.  (jemalloc calls these "dirty".) */
+        size_t  bookkeeping;    /* Committed bytes used internally by the
+                                   allocator. */
 } jemalloc_stats_t;
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
 #endif /* _JEMALLOC_TYPES_H_ */