From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sat, 25 Apr 2015 23:34:05 +0200 Subject: [PATCH] no-mallinfo: guard glibc mallinfo()/mlockall policy behind __GLIBC__ _allocate_memory()'s heap-growth probing uses glibc's MALLINFO/mallinfo(), which musl doesn't provide; guard it behind #ifdef __GLIBC__ and always grow by the full alloc_size on musl instead. Likewise _lock_mem() reads activation/use_mlockall from lvm.conf on glibc but always uses mlockall unconditionally on musl, where the glibc-specific heuristic this option tunes doesn't apply. Signed-off-by: Daniel Golle --- lib/mm/memlock.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/lib/mm/memlock.c +++ b/lib/mm/memlock.c @@ -209,12 +209,15 @@ static void _allocate_memory(void) * memory on free(), this is good enough for our purposes. */ while (missing > 0) { +#ifdef __GLIBC__ struct MALLINFO inf = MALLINFO(); hblks = inf.hblks; +#endif if ((areas[area] = malloc(alloc_size))) _touch_memory(areas[area], alloc_size); +#ifdef __GLIBC__ inf = MALLINFO(); if (hblks < inf.hblks) { @@ -224,9 +227,12 @@ static void _allocate_memory(void) free(areas[area]); alloc_size /= 2; } else { +#endif ++ area; missing -= alloc_size; +#ifdef __GLIBC__ } +#endif if (area == MAX_AREAS && missing > 0) { /* Too bad. Warn the user and proceed, as things are @@ -565,8 +571,13 @@ static void _lock_mem(struct cmd_context * will not block memory locked thread * Note: assuming _memlock_count_daemon is updated before _memlock_count */ +#ifdef __GLIBC__ _use_mlockall = _memlock_count_daemon ? 1 : find_config_tree_bool(cmd, activation_use_mlockall_CFG, NULL); +#else + /* always use mlockall on musl */ + _use_mlockall = 1; +#endif if (!_use_mlockall) { if (!*_procselfmaps &&