From 801fe3af80eb7d6993f162586ac6d00d308871af Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Tue, 30 Apr 2019 17:45:48 -0700 Subject: Remove unused stats from cache structure. Removing the stats make the whole cache structure fit in a single page. Bug: 131362671 Test: Verified that all bionic malloc benchmarks are still the same. Test: It turns out that the malloc_sql benchmarks seem to get faster. Test: Verified that after this change, it saves about 2K PSS per thread. Change-Id: I4dcd633543f05f1a9d47db175f9977ddb42188a9 (cherry picked from commit a8b52518654725e64def5ebbd0ed472100e5a522) --- include/jemalloc/internal/cache_bin.h | 3 +++ include/jemalloc/internal/tcache_inlines.h | 4 ++++ src/arena.c | 4 ++++ src/tcache.c | 16 ++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h index 12f3ef2d..bf73c7d1 100644 --- a/include/jemalloc/internal/cache_bin.h +++ b/include/jemalloc/internal/cache_bin.h @@ -46,12 +46,15 @@ struct cache_bin_s { cache_bin_sz_t low_water; /* # of cached objects. */ cache_bin_sz_t ncached; + /* Removing this variable make the cache_t structure fit in a single page. */ +#if defined(ANDROID_ENABLE_TCACHE_STATS) /* * ncached and stats are both modified frequently. Let's keep them * close so that they have a higher chance of being on the same * cacheline, thus less write-backs. */ cache_bin_stats_t tstats; +#endif /* * Stack of available objects. * diff --git a/include/jemalloc/internal/tcache_inlines.h b/include/jemalloc/internal/tcache_inlines.h index 0f6ab8cb..0859c4e7 100644 --- a/include/jemalloc/internal/tcache_inlines.h +++ b/include/jemalloc/internal/tcache_inlines.h @@ -90,9 +90,11 @@ tcache_alloc_small(tsd_t *tsd, arena_t *arena, tcache_t *tcache, memset(ret, 0, usize); } +#if defined(ANDROID_ENABLE_TCACHE_STATS) if (config_stats) { bin->tstats.nrequests++; } +#endif if (config_prof) { tcache->prof_accumbytes += usize; } @@ -148,9 +150,11 @@ tcache_alloc_large(tsd_t *tsd, arena_t *arena, tcache_t *tcache, size_t size, memset(ret, 0, usize); } +#if defined(ANDROID_ENABLE_TCACHE_STATUS) if (config_stats) { bin->tstats.nrequests++; } +#endif if (config_prof) { tcache->prof_accumbytes += usize; } diff --git a/src/arena.c b/src/arena.c index 5d55bf1a..61b8083f 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1289,10 +1289,14 @@ arena_tcache_fill_small(tsdn_t *tsdn, arena_t *arena, tcache_t *tcache, } if (config_stats) { bin->stats.nmalloc += i; +#if defined(ANDROID_ENABLE_TCACHE_STATS) bin->stats.nrequests += tbin->tstats.nrequests; +#endif bin->stats.curregs += i; bin->stats.nfills++; +#if defined(ANDROID_ENABLE_TCACHE_STATS) tbin->tstats.nrequests = 0; +#endif } malloc_mutex_unlock(tsdn, &bin->lock); tbin->ncached = i; diff --git a/src/tcache.c b/src/tcache.c index b4320e42..b2557c15 100644 --- a/src/tcache.c +++ b/src/tcache.c @@ -140,8 +140,10 @@ tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin, assert(!merged_stats); merged_stats = true; bin->stats.nflushes++; +#if defined(ANDROID_ENABLE_TCACHE_STATS) bin->stats.nrequests += tbin->tstats.nrequests; tbin->tstats.nrequests = 0; +#endif } unsigned ndeferred = 0; for (unsigned i = 0; i < nflush; i++) { @@ -176,8 +178,10 @@ tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin, bin_t *bin = &arena->bins[binind]; malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock); bin->stats.nflushes++; +#if defined(ANDROID_ENABLE_TCACHE_STATS) bin->stats.nrequests += tbin->tstats.nrequests; tbin->tstats.nrequests = 0; +#endif malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock); } @@ -192,7 +196,9 @@ tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin, void tcache_bin_flush_large(tsd_t *tsd, cache_bin_t *tbin, szind_t binind, unsigned rem, tcache_t *tcache) { +#if defined(ANDROID_ENABLE_TCACHE_STATS) bool merged_stats = false; +#endif assert(binind < nhbins); assert((cache_bin_sz_t)rem <= tbin->ncached); @@ -232,6 +238,7 @@ tcache_bin_flush_large(tsd_t *tsd, cache_bin_t *tbin, szind_t binind, tcache->prof_accumbytes); tcache->prof_accumbytes = 0; } +#if defined(ANDROID_ENABLE_TCACHE_STATS) if (config_stats) { merged_stats = true; arena_stats_large_nrequests_add(tsd_tsdn(tsd), @@ -239,6 +246,7 @@ tcache_bin_flush_large(tsd_t *tsd, cache_bin_t *tbin, szind_t binind, tbin->tstats.nrequests); tbin->tstats.nrequests = 0; } +#endif } malloc_mutex_unlock(tsd_tsdn(tsd), &locked_arena->large_mtx); @@ -269,6 +277,7 @@ tcache_bin_flush_large(tsd_t *tsd, cache_bin_t *tbin, szind_t binind, ndeferred); nflush = ndeferred; } +#if defined(ANDROID_ENABLE_TCACHE_STATS) if (config_stats && !merged_stats) { /* * The flush loop didn't happen to flush to this thread's @@ -278,6 +287,7 @@ tcache_bin_flush_large(tsd_t *tsd, cache_bin_t *tbin, szind_t binind, binind, tbin->tstats.nrequests); tbin->tstats.nrequests = 0; } +#endif memmove(tbin->avail - rem, tbin->avail - tbin->ncached, rem * sizeof(void *)); @@ -466,17 +476,21 @@ tcache_flush_cache(tsd_t *tsd, tcache_t *tcache) { cache_bin_t *tbin = tcache_small_bin_get(tcache, i); tcache_bin_flush_small(tsd, tcache, tbin, i, 0); +#if defined(ANDROID_ENABLE_TCACHE_STATS) if (config_stats) { assert(tbin->tstats.nrequests == 0); } +#endif } for (unsigned i = NBINS; i < nhbins; i++) { cache_bin_t *tbin = tcache_large_bin_get(tcache, i); tcache_bin_flush_large(tsd, tbin, i, 0, tcache); +#if defined(ANDROID_ENABLE_TCACHE_STATS) if (config_stats) { assert(tbin->tstats.nrequests == 0); } +#endif } if (config_prof && tcache->prof_accumbytes > 0 && @@ -531,6 +545,7 @@ tcache_cleanup(tsd_t *tsd) { void tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena) { +#if defined(ANDROID_ENABLE_TCACHE_STATS) unsigned i; cassert(config_stats); @@ -551,6 +566,7 @@ tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena) { tbin->tstats.nrequests); tbin->tstats.nrequests = 0; } +#endif } static bool -- cgit v1.2.3