MINOR: compat: automatically include malloc.h on glibc
authorWilly Tarreau <w@1wt.eu>
Tue, 3 Nov 2020 14:50:40 +0000 (15:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 May 2021 05:56:36 +0000 (07:56 +0200)
This is in order to access malloc_trim() which is convenient after
clearing huge maps to reclaim memory. When this is detected, we also
define HA_HAVE_MALLOC_TRIM.

(cherry picked from commit 1d3c7003d91a2c3b48f0f1fee3eb361f4121057b)
[wt: CONFIG_HAP_NO_GLOBAL_POOLS was backported via commitc0457dc81
     but the optional HA_HAVE_MALLOC_TRIM was never set, and it was
     shown to help in some cases]
Signed-off-by: Willy Tarreau <w@1wt.eu>

include/haproxy/compat.h

index 93dd5f2..8d02a7f 100644 (file)
@@ -240,6 +240,15 @@ typedef struct { } empty_t;
 #endif
 #endif
 
+/* malloc_trim() can be very convenient to reclaim unused memory especially
+ * from huge pattern files. It's available (and really usable) in glibc 2.8 and
+ * above.
+ */
+#if (defined(__GNU_LIBRARY__) && (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 8))
+#include <malloc.h>
+#define HA_HAVE_MALLOC_TRIM
+#endif
+
 /* glibc 2.26 includes a thread-local cache which makes it fast enough in threads */
 #if (defined(__GNU_LIBRARY__) && (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 26))
 #include <malloc.h>