Commit 079ebe3f authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

Merge branch 'sam/malloc-trim-glibc-only' into 'master'

malloc_trim() is not available in musl libc

Closes #135

See merge request !271
parents 40f55916 3f6e4f38
Pipeline #216316 failed with stages
in 2 minutes and 24 seconds
......@@ -50,6 +50,9 @@
/* Define if we have libseccomp */
#mesondefine HAVE_LIBSECCOMP
/* Define if we have malloc_trim() */
#mesondefine HAVE_MALLOC_TRIM
/* Define if we have NetworkManager for network status detection */
#mesondefine HAVE_NETWORK_MANAGER
......
......@@ -328,6 +328,8 @@ endif
conf = configuration_data()
have_malloc_trim = meson.get_compiler('c').has_function('malloc_trim')
# Config that goes in config.h
conf.set('GUARANTEE_METADATA', get_option('guarantee_metadata') == true)
conf.set('USING_UNZIPPSFILES', get_option('unzip_ps_gz_files') == true)
......@@ -344,6 +346,7 @@ conf.set('HAVE_LIBICU_CHARSET_DETECTION', charset_library_name == 'icu')
conf.set('HAVE_LIBEXIF', libexif.found())
conf.set('HAVE_LIBIPTCDATA', libiptcdata.found())
conf.set('HAVE_LIBSECCOMP', libseccomp.found())
conf.set('HAVE_MALLOC_TRIM', have_malloc_trim)
conf.set('HAVE_UPOWER', battery_detection_library_name == 'upower')
conf.set('HAVE_NETWORK_MANAGER', have_network_manager)
conf.set('DOMAIN_PREFIX', get_option('domain_prefix'))
......@@ -471,6 +474,7 @@ summary = [
'\nFeature Support:',
' Battery/mains power detection: ' + battery_detection_library_name,
' Support for network status detection: ' + have_network_manager.to_string(),
' Releasing heap memory with malloc_trim: ' + have_malloc_trim.to_string(),
'\nData Miners / Writebacks:',
' FS (File System): ' + have_tracker_miner_fs.to_string(),
' RSS: ' + have_tracker_miner_rss.to_string(),
......
......@@ -26,6 +26,10 @@
#include <sys/types.h>
#include <unistd.h>
#ifdef HAVE_MALLOC_TRIM
#include <malloc.h>
#endif
#include <glib.h>
#include <glib-unix.h>
#include <glib-object.h>
......@@ -433,11 +437,28 @@ miner_start (TrackerMiner *miner,
miner);
}
#ifdef HAVE_MALLOC_TRIM
static void
release_heap_memory (void)
{
malloc_trim (0);
}
#else
static void
release_heap_memory (void)
{
g_debug ("release_heap_memory(): Doing nothing as malloc_trim() is not available on this platform.");
}
#endif
static gboolean
cleanup_cb (gpointer user_data)
{
/* Reclaim as much memory as possible */
malloc_trim (0);
release_heap_memory ();
cleanup_id = 0;
......@@ -451,7 +472,7 @@ on_low_memory (GMemoryMonitor *monitor,
gpointer user_data)
{
if (level > G_MEMORY_MONITOR_WARNING_LEVEL_LOW)
malloc_trim (0);
release_heap_memory ();
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment