]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pool: support purging jemalloc arenas in trim_all_pools()
authorDavid Carlier <devnexen@gmail.com>
Thu, 25 Nov 2021 16:14:38 +0000 (16:14 +0000)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Nov 2021 17:54:50 +0000 (18:54 +0100)
In the case of Linux/glibc, falling back to malloc_trim if jemalloc
had not been detected beforehand.

src/pool.c

index 514a53e12ff5fb73bac0f1db4e5d29336e69a0ec..1d4f2dfbcc979075cb9ba7928874a90716937381 100644 (file)
@@ -48,10 +48,23 @@ static int(*my_mallctl)(const char *, void *, size_t *, void *, size_t) = NULL;
 /* ask the allocator to trim memory pools */
 static void trim_all_pools(void)
 {
+       if (my_mallctl) {
+               unsigned int i, narenas = 0;
+               size_t len = sizeof(narenas);
+
+               if (my_mallctl("arenas.narenas", &narenas, &len, NULL, 0) == 0) {
+                       for (i = 0; i < narenas; i ++) {
+                               char mib[32] = {0};
+                               snprintf(mib, sizeof(mib), "arena.%u.purge", i);
+                               (void)my_mallctl(mib, NULL, NULL, NULL, 0);
+                       }
+               }
+       } else {
 #if defined(HA_HAVE_MALLOC_TRIM)
-       if (using_default_allocator)
-               malloc_trim(0);
+               if (using_default_allocator)
+                       malloc_trim(0);
 #endif
+       }
 }
 
 /* check if we're using the same allocator as the one that provides