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)
diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h
index 12f3ef2..bf73c7d 100644
--- a/include/jemalloc/internal/cache_bin.h
+++ b/include/jemalloc/internal/cache_bin.h
@@ -46,12 +46,15 @@
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 0f6ab8c..0859c4e 100644
--- a/include/jemalloc/internal/tcache_inlines.h
+++ b/include/jemalloc/internal/tcache_inlines.h
@@ -90,9 +90,11 @@
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 @@
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 5d55bf1..61b8083 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -1289,10 +1289,14 @@
}
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 b4320e4..b2557c1 100644
--- a/src/tcache.c
+++ b/src/tcache.c
@@ -140,8 +140,10 @@
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 @@
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 @@
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->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 @@
tbin->tstats.nrequests);
tbin->tstats.nrequests = 0;
}
+#endif
}
malloc_mutex_unlock(tsd_tsdn(tsd), &locked_arena->large_mtx);
@@ -269,6 +277,7 @@
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 @@
binind, tbin->tstats.nrequests);
tbin->tstats.nrequests = 0;
}
+#endif
memmove(tbin->avail - rem, tbin->avail - tbin->ncached, rem *
sizeof(void *));
@@ -466,17 +476,21 @@
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 @@
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 @@
tbin->tstats.nrequests);
tbin->tstats.nrequests = 0;
}
+#endif
}
static bool