diff --git a/src/main.cpp b/src/main.cpp index 1657cdd089c6152ddf81b3fb7260026b396b4cde..7b3b3be3be9e08ae14d7cc6ea5d011adbb0f01c3 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)); }