Add support for modifying decay timer.
Add the mallopt function, and only a single option so far.
Bug: 36401135
Test: Built and booted bullhead.
Test: Ran jemalloc unit tests.
Test: Ran bionic unit tests.
Test: Ran a test that allocated and free'd a large piece of memory,
Test: and verified that after changing the parameter, the PSS
Test: sticks around (decay timer set to 1), the PSS is purged (decay
Test: timer set to 0).
Change-Id: I6927929b0c539c1023d34772d9e26bb6a8a45877
diff --git a/libc/bionic/malloc_common.cpp b/libc/bionic/malloc_common.cpp
index 18c998d..1f201d1 100644
--- a/libc/bionic/malloc_common.cpp
+++ b/libc/bionic/malloc_common.cpp
@@ -68,6 +68,7 @@
Malloc(iterate),
Malloc(malloc_disable),
Malloc(malloc_enable),
+ Malloc(mallopt),
};
// In a VM process, this is set to 1 after fork()ing out of zygote.
@@ -101,6 +102,14 @@
return Malloc(mallinfo)();
}
+extern "C" int mallopt(int param, int value) {
+ auto _mallopt = __libc_globals->malloc_dispatch.mallopt;
+ if (__predict_false(_mallopt != nullptr)) {
+ return _mallopt(param, value);
+ }
+ return Malloc(mallopt)(param, value);
+}
+
extern "C" void* malloc(size_t bytes) {
auto _malloc = __libc_globals->malloc_dispatch.malloc;
if (__predict_false(_malloc != nullptr)) {
@@ -247,6 +256,10 @@
prefix, "mallinfo")) {
return false;
}
+ if (!InitMallocFunction<MallocMallopt>(malloc_impl_handler, &table->mallopt,
+ prefix, "mallopt")) {
+ return false;
+ }
if (!InitMallocFunction<MallocMalloc>(malloc_impl_handler, &table->malloc,
prefix, "malloc")) {
return false;