e system - force a malloc trim regularly to keep back-end proc minimal

This commit is contained in:
Carsten Haitzler 2020-01-16 12:09:49 +00:00
parent 63ae3290fb
commit 5b5c7c3cb3
3 changed files with 22 additions and 0 deletions

View File

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

View File

@ -66,6 +66,9 @@ void *alloca (size_t);
# include <inttypes.h>
# include <assert.h>
# include <fcntl.h>
# ifdef HAVE_MALLOC_H
# include <malloc.h>
# endif
#if defined (__FreeBSD__) || defined (__OpenBSD__)
# include <sys/sysctl.h>

View File

@ -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();