From 973e50d1f43b680863551f1aea30d88616488e84 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 28 Sep 2024 00:27:08 +0200 Subject: FreeBSD/jemalloc: fixed recovery after hitting memory limit * We now set opt.retain=false for the process, so jemalloc returns freed memory and the RSS decreases when recovering from memory limit hits. This should be safe at least on FreeBSD. * Either the opt.retain option is new or I was previously testing this only on 32-bit systems. --- src/memory.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/memory.c b/src/memory.c index 605c221..26cde55 100644 --- a/src/memory.c +++ b/src/memory.c @@ -495,6 +495,16 @@ teco_memory_get_usage(void) return procstk.ki_rssize * page_size; } +/** + * Options passed to jemalloc. + * + * It's crucial to disable opt.retain, so that freeing memory after + * recovering from memory limit hits actually decreases the RSS. + * The reasons for activating the option, mentioned in jemalloc(3), + * shouldn't be relevant on FreeBSD. + */ +const gchar *malloc_conf = "retain:false"; + #define NEED_POLL_THREAD #elif defined(G_OS_UNIX) && defined(HAVE_SYSCONF) && defined(HAVE_PROCFS) -- cgit v1.2.3