summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2020-03-10 20:12:02 -0700
committerBenjamin Berg <benjamin@sipsolutions.net>2020-03-20 10:25:29 +0000
commit7e351b3da75252c0085ec8eaccecf56fe9f3ca73 (patch)
treede8d75b135ffa4b83368352fdd7268b9dc3ac671
parente0282e8be8b6ca0d5e50c8789ef6db08a8ef492f (diff)
downloadgnome-settings-daemon-wip/chergert/mem-reduce.tar.gz
datetime: use malloc_trim() to release resources back to OSwip/chergert/mem-reduce
We allocate a lot of memory while building the timezone database from libgweather all to have that put into the GSlice allocation queues we'll barely if ever touch again. By forcing things to use malloc, we can use malloc_trim() on supported GLibc systems to madvise() the kernel it can take the memory back. With the previous patches and this, gsd-datetime drops from about 9MB down to just under 3MB. We could probably go even further if we change libgweather a bit, but this gets it small enough for me. However, there are other processes (such as evolution-calendar-factory) that would benefit from a more generic solution. It's also very likely that we would want to just make gsd-datetime activatable through external events so the process can go away entirely.
-rw-r--r--meson.build9
-rw-r--r--plugins/datetime/gsd-datetime.service.in2
-rw-r--r--plugins/datetime/weather-tz.c12
3 files changed, 23 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index cd8616cb..578ae07a 100644
--- a/meson.build
+++ b/meson.build
@@ -219,6 +219,15 @@ if enable_network_manager
endif
config_h.set10('HAVE_NETWORK_MANAGER', enable_network_manager)
+# check for malloc_trim(0)
+malloc_trim_code = '''
+#include <malloc.h>
+void func() { malloc_trim(0); }
+'''
+if cc.compiles(malloc_trim_code, name: 'malloc_trim')
+ config_h.set10('HAVE_MALLOC_TRIM', 1)
+endif
+
gnome = import('gnome')
i18n = import('i18n')
pkg = import('pkgconfig')
diff --git a/plugins/datetime/gsd-datetime.service.in b/plugins/datetime/gsd-datetime.service.in
index bd4692b8..0607087f 100644
--- a/plugins/datetime/gsd-datetime.service.in
+++ b/plugins/datetime/gsd-datetime.service.in
@@ -17,3 +17,5 @@ ExecStart=@libexecdir@/gsd-datetime
Restart=on-failure
BusName=@plugin_dbus_name@
TimeoutStopSec=5
+# gsd-datetime will use malloc_trim()
+Environment=G_SLICE=always-malloc
diff --git a/plugins/datetime/weather-tz.c b/plugins/datetime/weather-tz.c
index f4afdaca..47fa6d31 100644
--- a/plugins/datetime/weather-tz.c
+++ b/plugins/datetime/weather-tz.c
@@ -24,6 +24,9 @@
#endif
#include <dlfcn.h>
+#ifdef HAVE_MALLOC_TRIM
+# include <malloc.h>
+#endif
#include "weather-tz.h"
#include "tz.h"
@@ -112,6 +115,15 @@ release_world (void)
if (release_world_func != NULL) {
g_debug ("Releasing Locations.xml data");
release_world_func ();
+
+#ifdef HAVE_MALLOC_TRIM
+ /* A lot of the memory we just allocated won't be released back
+ * to the operating system unless malloc is told to release it.
+ * This also pretty much relies on G_SLICE=always-malloc so
+ * that libgweather does not allocate everything with gslice.
+ */
+ malloc_trim (0);
+#endif
}
else {
g_debug ("Cannot locate symbol _gweather_location_reset_world()");