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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3653>
This commit is contained in:
Sebastian Keller 2024-03-08 11:59:40 +01:00 committed by Marge Bot
parent 6d03666d2d
commit f94e32037c
3 changed files with 14 additions and 0 deletions

View File

@ -132,3 +132,6 @@
/* Supports timerfd_create/timerfd_settime */
#mesondefine HAVE_TIMERFD
/* Supports malloc_trim */
#mesondefine HAVE_MALLOC_TRIM

View File

@ -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')

View File

@ -23,6 +23,10 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gio/gio.h>
#ifdef HAVE_MALLOC_TRIM
#include <malloc.h>
#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);