blob: fb429b50898e047473e3f05bcb037f489e53f34a (
plain) (
blame)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
x86: 0.946
graphic: 0.840
device: 0.833
arm: 0.818
architecture: 0.784
PID: 0.726
semantic: 0.651
permissions: 0.603
ppc: 0.590
debug: 0.560
vnc: 0.552
performance: 0.476
kernel: 0.453
assembly: 0.384
register: 0.375
socket: 0.329
peripherals: 0.313
network: 0.311
VMM: 0.288
user-level: 0.247
risc-v: 0.201
hypervisor: 0.182
mistranslation: 0.159
boot: 0.128
files: 0.102
TCG: 0.068
virtual: 0.063
KVM: 0.042
i386: 0.026
Memory leak for x86 guest on macOS ARM host
Description of problem:
QEMU is used by docker to run `x86` binaries on Apple silicon. Then using `mmap` followed by `munmap` results in a memory leak manifested by continuously growing RSS memory usage when running `mmap` and `munmap` in a loop, e.g., when running the following binary:
```
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
const int page = 4096;
int work(int N) {
int *ptr = mmap(NULL, N * sizeof(int), PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (ptr == MAP_FAILED) {
printf("Mapping Failed\n");
return 1;
}
for(int i = 0; i < N; i++) {
ptr[i] = i * 10;
}
int err = munmap(ptr, N * sizeof(int));
if (err != 0) {
printf("UnMapping Failed\n");
return 1;
}
return 0;
}
int main() {
int N = page * 1024;
while (1) {
int res = work(N);
if (res) {
return res;
}
printf(".\n");
}
return 0;
}
```
Steps to reproduce:
```
$ LEAK=$(docker run --platform linux/amd64 -d -it martin2718/mmap-leak ./a.out)
$ docker exec -it $LEAK top # you should observe that RES for a.out keeps growing
$ docker exec -it $LEAK pmap -x 1 # you should see a single memory mapping whose RSS memory usage keeps growing
$ docker kill $LEAK # abort the experiment
```
|