From 218f766e21bf7cfe3cb45c3c34a951cb719c1d57 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 4 Apr 2018 17:53:54 -0700 Subject: [PATCH] adbd: configure jemalloc to not immediately purge. Profiling of adb_benchmark revealed that something like half of the CPU time was being spent in malloc and free, which was odd because the benchmark repeatedly mallocs and frees allocations of the same size. It turns out that our default configuration of jemalloc will purge after every free. Configure jemalloc to not do this, for gains of over 100% on adb_benchmark, and up to 25% (on walleye USB3) in real-life. Test: adb_benchmark Change-Id: I602dd1645c3d21709c7f6a78903511ce4d576558 --- adb/daemon/main.cpp | 6 +++++- adb/transport_benchmark.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp index 4314dae0b..527a264f6 100644 --- a/adb/daemon/main.cpp +++ b/adb/daemon/main.cpp @@ -19,10 +19,11 @@ #include "sysdeps.h" #include +#include +#include #include #include #include -#include #include #include @@ -213,6 +214,9 @@ int adbd_main(int server_port) { } int main(int argc, char** argv) { + // Set M_DECAY_TIME so that our allocations aren't immediately purged on free. + mallopt(M_DECAY_TIME, 1); + while (true) { static struct option opts[] = { {"root_seclabel", required_argument, nullptr, 's'}, diff --git a/adb/transport_benchmark.cpp b/adb/transport_benchmark.cpp index ffe4cbc8d..da24aa7a7 100644 --- a/adb/transport_benchmark.cpp +++ b/adb/transport_benchmark.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include @@ -171,6 +172,9 @@ ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::SameThread); ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::MainThread); int main(int argc, char** argv) { + // Set M_DECAY_TIME so that our allocations aren't immediately purged on free. + mallopt(M_DECAY_TIME, 1); + android::base::SetMinimumLogSeverity(android::base::WARNING); adb_trace_init(argv); ::benchmark::Initialize(&argc, argv);