From: Thomas Winter Date: Thu, 27 Apr 2023 04:08:46 +0000 (+1200) Subject: rule-reload: Release excess memory freed during engine reload X-Git-Tag: suricata-8.0.0-beta1~2052 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d40a9f178a3b8d686b1f33bfc1f6e21a662ccb3;p=thirdparty%2Fsuricata.git rule-reload: Release excess memory freed during engine reload The hot reload results in large chunks of memory being freed as the as the old signature tables are discarded. Help the memory management system along by telling to release as much memory as it can at this point. Bug: #6454. --- diff --git a/configure.ac b/configure.ac index 1eb054d98c..c2bed71761 100644 --- a/configure.ac +++ b/configure.ac @@ -220,6 +220,13 @@ #include ]) + AC_CHECK_HEADERS([malloc.h]) + AC_CHECK_DECL([malloc_trim], + AC_DEFINE([HAVE_MALLOC_TRIM], [1], [Use malloc_trim]), + [], [ + #include + ]) + OCFLAGS=$CFLAGS CFLAGS="" AC_CHECK_FUNCS([strlcpy strlcat]) diff --git a/src/detect-engine.c b/src/detect-engine.c index 0fc2df6869..25e76445ed 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -4797,6 +4797,15 @@ int DetectEngineReload(const SCInstance *suri) SCLogDebug("old_de_ctx should have been freed"); SCLogNotice("rule reload complete"); + +#ifdef HAVE_MALLOC_TRIM + /* The reload process potentially frees up large amounts of memory. + * Encourage the memory management system to reclaim as much as it + * can. + */ + malloc_trim(0); +#endif + return 0; } diff --git a/src/suricata-common.h b/src/suricata-common.h index 4aad25a252..297a6fc452 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -212,6 +212,10 @@ typedef unsigned char u_char; #include #endif +#if HAVE_MALLOC_H +#include +#endif + #if __CYGWIN__ #if !defined _X86_ && !defined __x86_64 #define _X86_