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
diff --git a/daemon/main.cpp b/daemon/main.cpp
index 4314dae..527a264 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -19,10 +19,11 @@
#include "sysdeps.h"
#include <errno.h>
+#include <getopt.h>
+#include <malloc.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include <getopt.h>
#include <sys/prctl.h>
#include <memory>
@@ -213,6 +214,9 @@
}
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'},