1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
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 <daniel@makrotopia.org>
---
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 &&
|