BUG/MINOR: pools: restore detection of built-in allocator
The runtime detection of the default memory allocator was broken by
Commit d8a97d8f6
("BUG/MINOR: illegal use of the malloc_trim() function
if jemalloc is used") due to a misunderstanding of its role. The purpose
is not to detect whether we're on non-jemalloc but whether or not the
allocator was changed from the one we booted with, in which case we must
be extra cautious and absolutely refrain from calling malloc_trim() and
its friends.
This was done only to drop the message saying that malloc_trim() is
supported, which will be totally removed in another commit, and could
possibly be removed even in older versions if this patch would get
backported since in the end it provides limited value.
This commit is contained in:
parent
c3b297d5a4
commit
0c27ec5df7
13
src/pool.c
13
src/pool.c
|
@ -105,7 +105,7 @@ struct show_pools_ctx {
|
|||
};
|
||||
|
||||
static int mem_fail_rate __read_mostly = 0;
|
||||
static int using_default_allocator __read_mostly = 1;
|
||||
static int using_default_allocator __read_mostly = 1; // linked-in allocator or LD_PRELOADed one ?
|
||||
static int disable_trim __read_mostly = 0;
|
||||
static int(*my_mallctl)(const char *, void *, size_t *, void *, size_t) = NULL;
|
||||
static int(*_malloc_trim)(size_t) = NULL;
|
||||
|
@ -144,10 +144,17 @@ static void detect_allocator(void)
|
|||
|
||||
my_mallctl = mallctl;
|
||||
#endif
|
||||
if (!my_mallctl)
|
||||
if (!my_mallctl) {
|
||||
/* trick: we won't enter here if mallctl() is known at link
|
||||
* time. This allows to detect if the symbol was changed since
|
||||
* the program was linked, indicating it's not running on the
|
||||
* expected allocator (due to an LD_PRELOAD) and that we must
|
||||
* be extra cautious and avoid some optimizations that are
|
||||
* known to break such as malloc_trim().
|
||||
*/
|
||||
my_mallctl = get_sym_curr_addr("mallctl");
|
||||
|
||||
using_default_allocator = (my_mallctl == NULL);
|
||||
}
|
||||
|
||||
if (!my_mallctl) {
|
||||
#if defined(HA_HAVE_MALLOC_TRIM)
|
||||
|
|
Loading…
Reference in New Issue