From a0ab32276adbc157ebdadd922fb7a45bd99c68c7 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Mon, 18 Mar 2024 16:06:02 -0400 Subject: [PATCH] PR31103: debuginfod: periodically call malloc_trim(0) Add malloc_trim() for releasing memory which is allocated for temporary purposes, e.g. answering queries, adding data to the database during scans. This patch just adds one call after the groom cycle, but others could be added around webapi query handling or scanning ops too. Signed-off-by: Di Chen --- configure.ac | 2 ++ debuginfod/debuginfod.cxx | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index bbe8673e..098d1306 100644 --- a/configure.ac +++ b/configure.ac @@ -483,6 +483,8 @@ AC_CHECK_HEADERS([sched.h]) AC_CHECK_FUNCS([sched_getaffinity]) AC_CHECK_HEADERS([sys/resource.h]) AC_CHECK_FUNCS([getrlimit]) +AC_CHECK_HEADERS([malloc.h]) +AC_CHECK_FUNCS([malloc_trim]) old_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -D_GNU_SOURCE" diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 72617848..ece5031f 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -49,6 +49,11 @@ extern "C" { #include } #endif +#ifdef HAVE_MALLOC_H +extern "C" { +#include +} +#endif #include "debuginfod.h" #include @@ -4226,9 +4231,11 @@ void groom() sqlite3_db_release_memory(db); // shrink the process if possible sqlite3_db_release_memory(dbq); // ... for both connections debuginfod_pool_groom(); // and release any debuginfod_client objects we've been holding onto - -#if 0 /* PR31265: don't jettison cache unnecessarily */ +#if HAVE_MALLOC_TRIM + malloc_trim(0); // PR31103: release memory allocated for temporary purposes +#endif +#if 0 /* PR31265: don't jettison cache unnecessarily */ fdcache.limit(0); // release the fdcache contents fdcache.limit(fdcache_mbs); // restore status quo parameters #endif -- 2.47.2