In the event that HAProxy is linked with the jemalloc library, it is still
shown that malloc_trim() is enabled when executing "haproxy -vv":
..
Support for malloc_trim() is enabled.
..
It's not so much a problem as it is that malloc_trim() is called in the
pat_ref_purge_range() function without any checking.
This was solved by setting the using_default_allocator variable to the
correct value in the detect_allocator() function and before calling
malloc_trim() it is checked whether the function should be called.
/* set of POOL_DBG_* flags */
extern uint pool_debugging;
+int is_trim_enabled(void);
void *pool_get_from_os(struct pool_head *pool);
void pool_put_to_os(struct pool_head *pool, void *ptr);
void *pool_alloc_nocache(struct pool_head *pool);
HA_RWLOCK_WRUNLOCK(PATEXP_LOCK, &expr->lock);
#if defined(HA_HAVE_MALLOC_TRIM)
- if (done) {
+ if (done && is_trim_enabled()) {
malloc_trim(0);
}
#endif
my_mallctl = mallctl;
#endif
-
- if (!my_mallctl) {
+ if (!my_mallctl)
my_mallctl = get_sym_curr_addr("mallctl");
- using_default_allocator = (my_mallctl == NULL);
- }
+
+ using_default_allocator = (my_mallctl == NULL);
if (!my_mallctl) {
#if defined(HA_HAVE_MALLOC_TRIM)
}
}
-static int is_trim_enabled(void)
+int is_trim_enabled(void)
{
return using_default_allocator;
}