]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
PR31103: debuginfod: periodically call malloc_trim(0)
authorFrank Ch. Eigler <fche@redhat.com>
Mon, 18 Mar 2024 20:06:02 +0000 (16:06 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Mon, 18 Mar 2024 20:06:02 +0000 (16:06 -0400)
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 <dichen@redhat.com>
configure.ac
debuginfod/debuginfod.cxx

index bbe8673e413a84483df8920872f4ee7f2807f861..098d13067ee6265b3893e2953efc6cc10fed297c 100644 (file)
@@ -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"
index 72617848d0dd1cac36ebefa9ffa358344e13bd58..ece5031f02f9a582be4602d5475a38fe1787e3ed 100644 (file)
@@ -49,6 +49,11 @@ extern "C" {
 #include <execinfo.h>
 }
 #endif
+#ifdef HAVE_MALLOC_H
+extern "C" {
+#include <malloc.h>
+}
+#endif
 
 #include "debuginfod.h"
 #include <dwarf.h>
@@ -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