From e67b738ee5897731029bf36dd3a2eef82ab76dd3 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Mon, 29 Jul 2013 09:10:53 -0700 Subject: [PATCH] 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. --HG-- extra : rebase_source : 429f3d44011f02dda43aa10b077c917c4d02fe50 --- memory/mozjemalloc/jemalloc.c | 28 +++++++++++++++++----------- memory/mozjemalloc/jemalloc_types.h | 11 ++++++++--- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/memory/mozjemalloc/jemalloc.c b/memory/mozjemalloc/jemalloc.c index ac87e8fdb0c7..5ee8682f0be8 100644 --- a/memory/mozjemalloc/jemalloc.c +++ b/memory/mozjemalloc/jemalloc.c @@ -6725,14 +6725,14 @@ jemalloc_stats_impl(jemalloc_stats_t *stats) * 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); @@ -6740,25 +6740,31 @@ jemalloc_stats_impl(jemalloc_stats_t *stats) 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 diff --git a/memory/mozjemalloc/jemalloc_types.h b/memory/mozjemalloc/jemalloc_types.h index 99b739c76b74..0cf964b4d752 100644 --- a/memory/mozjemalloc/jemalloc_types.h +++ b/memory/mozjemalloc/jemalloc_types.h @@ -72,9 +72,14 @@ typedef struct { * 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