From 5b5c7c3cb3d5e3332ecc714fb7946039db65fb61 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Thu, 16 Jan 2020 12:09:49 +0000 Subject: [PATCH] e system - force a malloc trim regularly to keep back-end proc minimal --- meson.build | 6 ++++++ src/bin/system/e_system.h | 3 +++ src/bin/system/e_system_main.c | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/meson.build b/meson.build index a1fa4ae15..3d53a720c 100644 --- a/meson.build +++ b/meson.build @@ -154,6 +154,12 @@ if cc.has_header('sys/procctl.h') == true config_h.set('HAVE_PROCCTL' , '1') endif +if cc.has_header('malloc.h') == true + config_h.set('HAVE_MALLOC_H' , '1') +endif +if cc.has_function('malloc_trim') == true + config_h.set('HAVE_MALLOC_TRIM' , '1') +endif if cc.has_function('setenv') == true config_h.set('HAVE_SETENV' , '1') endif diff --git a/src/bin/system/e_system.h b/src/bin/system/e_system.h index dad7fc65a..c956c7a2f 100644 --- a/src/bin/system/e_system.h +++ b/src/bin/system/e_system.h @@ -66,6 +66,9 @@ void *alloca (size_t); # include # include # include +# ifdef HAVE_MALLOC_H +# include +# endif #if defined (__FreeBSD__) || defined (__OpenBSD__) # include diff --git a/src/bin/system/e_system_main.c b/src/bin/system/e_system_main.c index f355b57d4..de7873ade 100644 --- a/src/bin/system/e_system_main.c +++ b/src/bin/system/e_system_main.c @@ -257,6 +257,17 @@ singleton_setup(void) ecore_thread_feedback_run(_cb_die, NULL, NULL, NULL, NULL, EINA_TRUE); } +static Eina_Bool +_cb_idle_enterer(void *data EINA_UNUSED) +{ + // welcome to unportable code land... :) + // trim process down as much as possible when going idle +#ifdef HAVE_MALLOC_TRIM + malloc_trim(0); +#endif + return ECORE_CALLBACK_RENEW; +} + int main(int argc EINA_UNUSED, const char **argv EINA_UNUSED) { @@ -282,6 +293,8 @@ main(int argc EINA_UNUSED, const char **argv EINA_UNUSED) e_system_l2ping_init(); e_system_cpufreq_init(); + ecore_idle_enterer_add(_cb_idle_enterer, NULL); + ecore_main_loop_begin(); e_system_cpufreq_shutdown();