From dc23cc80210799f8d8ab5b1ea2e00341e613a1a7 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Thu, 8 Dec 2022 16:32:56 +0000 Subject: cheri: malloc: Set fixed mmap_threshold for capability narrowing Capability narrowing requires extra alignment for large allocations, this can cause significant heap fragmentation so ensure large allocations use a single mmap and unmaped on free. The fragmentation is bug 14581. This patch disables dynamic mmap threshold when cap_narrowing is enabled and uses a threshold of 256 kbytes on morello (which means at most 64 byte alignment requirement on the heap). The dynamic threshold could quickly grow very big and stay there making the fragmentation issue common. --- malloc/arena.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'malloc') diff --git a/malloc/arena.c b/malloc/arena.c index c63cb70f74..05df8c1510 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -331,7 +331,13 @@ ptmalloc_init (void) if (TUNABLE_GET_FULL (glibc, mem, cap_narrowing, int32_t, NULL) == 0) cap_narrowing_enabled = false; else - cap_narrowing_enabled = true; + { + cap_narrowing_enabled = true; +# ifdef __CAP_MMAP_THRESHOLD + /* Default mmap threshold to avoid heap fragmentation. */ + do_set_mmap_threshold (__CAP_MMAP_THRESHOLD); +# endif + } #endif cap_init (); -- cgit v1.2.3