From f94e32037c3108d7f4bbe7aaf2c9f039d5834b68 Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Fri, 8 Mar 2024 11:59:40 +0100 Subject: [PATCH] background: Call malloc_trim() after loading background image Some of the new JXL backgrounds from gnome-backgrounds can allocate several hundred MB during loading, so let's call malloc_trim() after we are done with loading the image into a pixbuf. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3327 Part-of: --- config.h.meson | 3 +++ meson.build | 3 +++ src/compositor/meta-background-image.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/config.h.meson b/config.h.meson index 09e95b221..094d79616 100644 --- a/config.h.meson +++ b/config.h.meson @@ -132,3 +132,6 @@ /* Supports timerfd_create/timerfd_settime */ #mesondefine HAVE_TIMERFD + +/* Supports malloc_trim */ +#mesondefine HAVE_MALLOC_TRIM diff --git a/meson.build b/meson.build index 5a741631c..c2c9c8bb7 100644 --- a/meson.build +++ b/meson.build @@ -345,6 +345,8 @@ int main (int argc, char ** argv) { } ''', name : 'timerfd_create(2) system call') +have_malloc_trim = meson.get_compiler('c').has_function('malloc_trim') + have_documentation = get_option('docs') have_tests = get_option('tests') have_core_tests = false @@ -570,6 +572,7 @@ cdata.set('HAVE_PROFILER', have_profiler) cdata.set('HAVE_LIBDISPLAY_INFO', have_libdisplay_info) cdata.set('HAVE_PANGO_FT2', have_pango_ft2) cdata.set('HAVE_TIMERFD', have_timerfd) +cdata.set('HAVE_MALLOC_TRIM', have_malloc_trim) if have_x11_client xkb_base = xkeyboard_config_dep.get_variable('xkb_base') diff --git a/src/compositor/meta-background-image.c b/src/compositor/meta-background-image.c index c27c36e1b..508a63440 100644 --- a/src/compositor/meta-background-image.c +++ b/src/compositor/meta-background-image.c @@ -23,6 +23,10 @@ #include #include +#ifdef HAVE_MALLOC_TRIM +#include +#endif + #include "clutter/clutter.h" #include "compositor/cogl-utils.h" @@ -135,6 +139,10 @@ load_file (GTask *task, pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), NULL, &error); g_object_unref (stream); +#ifdef HAVE_MALLOC_TRIM + malloc_trim (0); +#endif + if (pixbuf == NULL) { g_task_return_error (task, error);