]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Disable multiple malloc arenas
authorMaria Matejka <mq@ucw.cz>
Sat, 14 Dec 2024 22:21:07 +0000 (23:21 +0100)
committerMaria Matejka <mq@ucw.cz>
Sun, 15 Dec 2024 21:21:34 +0000 (22:21 +0100)
In our usecase, these are impossibly greedy because we often
free memory in a different thread than where we allocate, forcing
the default allocator to scatter the used memory all over the place.

configure.ac
sysdep/unix/alloc.c

index e086019fb4c14f002837987bcc7682910dc186a1..a991945235cd3775186b24021eac1f1351a737d0 100644 (file)
@@ -371,6 +371,7 @@ esac
 AC_CHECK_HEADERS_ONCE([alloca.h syslog.h stdatomic.h])
 AC_CHECK_HEADER([sys/mman.h], [AC_DEFINE([HAVE_MMAP], [1], [Define to 1 if mmap() is available.])], have_mman=no)
 AC_CHECK_FUNC([aligned_alloc], [AC_DEFINE([HAVE_ALIGNED_ALLOC], [1], [Define to 1 if aligned_alloc() is available.])], have_aligned_alloc=no)
+AC_CHECK_HEADER([malloc.h], [AC_DEFINE([HAVE_MALLOC_H], [1], [Define to 1 if malloc.h is available.])], have_malloc_h=no)
 AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], [#include <sys/socket.h>])
 
 if test "$have_aligned_alloc" = "no" && test "$have_mman" = "no" ; then
index e3a96f8da858da224e8b8df397656de1c9956597..74618dfb843a5d9d8e9015469f8c2513bcc36a2d 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+
 #ifdef HAVE_MMAP
 # include <sys/mman.h>
 #endif
@@ -501,6 +505,11 @@ page_dump(struct dump_request *dreq)
 void
 resource_sys_init(void)
 {
+#ifdef HAVE_MALLOC_H
+  if (!mallopt(M_ARENA_MAX, 1))
+    log(L_WARN "Failed to disable multiple malloc arenas, memory consumption may skyrocket.");
+#endif
+
 #ifdef CONFIG_DISABLE_THP
   /* Disable transparent huge pages, they do not work properly with madvice(MADV_DONTNEED) */
   if (prctl(PR_SET_THP_DISABLE,  (unsigned long) 1,  (unsigned long) 0,  (unsigned long) 0,  (unsigned long) 0) < 0)