aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2019-05-01 13:26:46 -0700
committerChristopher Ferris <cferris@google.com>2019-05-01 13:32:20 -0700
commit58567dcd7837e7fe81f3235c32807185cb20a99d (patch)
treebbb6cab3c845af517dd1807a75b0b5c629b8649f
parent8dc7da51b537e301bf6ee05e7fb56e97df23a7d1 (diff)
downloadandroid_bionic-58567dcd7837e7fe81f3235c32807185cb20a99d.tar.gz
android_bionic-58567dcd7837e7fe81f3235c32807185cb20a99d.tar.bz2
android_bionic-58567dcd7837e7fe81f3235c32807185cb20a99d.zip
Make purging clear the current thread cache too.
Bug: 131362671 Test: Ran bionic unit tests. Test: Wrote a test that did a purge and verified that the tcache->ncached Test: number went from 3 to 0. Also verified that mallinfo reflects the Test: cached entries being flushed. Change-Id: I64e35618fa3b523cf29bdaceedef676abe440dd3 (cherry picked from commit 0f710fd59346312b4e351e9d3c956bc804ff02b2)
-rw-r--r--libc/bionic/jemalloc_wrapper.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
index bc3a9dcdf..fd99814a6 100644
--- a/libc/bionic/jemalloc_wrapper.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -103,6 +103,14 @@ int je_mallopt(int param, int value) {
}
return 1;
} else if (param == M_PURGE) {
+ // Only clear the current thread cache since there is no easy way to
+ // clear the caches of other threads.
+ // This must be done first so that cleared allocations get purged
+ // in the next calls.
+ if (je_mallctl("thread.tcache.flush", nullptr, nullptr, nullptr, 0) != 0) {
+ return 0;
+ }
+
unsigned narenas;
size_t sz = sizeof(unsigned);
if (je_mallctl("arenas.narenas", &narenas, &sz, nullptr, 0) != 0) {