From e86715dc1c72178c0772e68cd22a871f2f3813a2 Mon Sep 17 00:00:00 2001 From: ZhaoPengyuan Date: Tue, 18 Aug 2020 11:32:17 +0800 Subject: [PATCH] memory:optimize "Memory Fragmentation" set some malloc options --- src/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 1657cdd0..7b3b3be3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,8 +17,29 @@ #include "anbox/daemon.h" #include "anbox/utils.h" +#include int main(int argc, char **argv) { + /* Note: Nowadays, glibc uses a dynamic mmap threshold by + default. The initial value of the threshold is 128*1024, but + when blocks larger than the current threshold and less than or + equal to DEFAULT_MMAP_THRESHOLD_MAX are freed, the threshold + is adjusted upward to the size of the freed block. When + dynamic mmap thresholding is in effect, the threshold for + trimming the heap is also dynamically adjusted to be twice the + dynamic mmap threshold. Dynamic adjustment of the mmap + threshold is disabled if any of the M_TRIM_THRESHOLD, + M_TOP_PAD, M_MMAP_THRESHOLD, or M_MMAP_MAX parameters is set. */ + + constexpr int KILO_BYTES = 1024; + constexpr int DEFAULT_THRESHOLD = 128 * KILO_BYTES; + constexpr int DEFAULT_TOP_PAD = 128 * KILO_BYTES; + constexpr int DEFAULT_MMAP_MAX = 64 * KILO_BYTES; + mallopt(M_ARENA_MAX, 2); + mallopt(M_MMAP_THRESHOLD, DEFAULT_THRESHOLD); + mallopt(M_TRIM_THRESHOLD, DEFAULT_THRESHOLD); + mallopt(M_TOP_PAD, DEFAULT_TOP_PAD); + mallopt(M_MMAP_MAX, DEFAULT_MMAP_MAX); anbox::Daemon daemon; return daemon.Run(anbox::utils::collect_arguments(argc, argv)); } -- GitLab