-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmmap_big.cpp
44 lines (38 loc) · 1.11 KB
/
mmap_big.cpp
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
#include "faasm/faasm.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sys/mman.h>
int main(int argc, char* argv[])
{
// Make sure we can allocate more than 1GB of memory (i.e. >16384 pages)
size_t nPages = 18000;
size_t chunkSize = 1000;
size_t nChunks = nPages / chunkSize;
size_t chunkLen = (chunkSize * 64 * 1024);
void** regions = new void*[nChunks];
for (int i = 0; i < nChunks; i++) {
void* p = mmap(nullptr,
chunkLen,
PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE,
-1,
0);
if (p == MAP_FAILED) {
printf("ERROR - mmap failed: %s\n", strerror(errno));
return 1;
}
regions[i] = p;
}
for (int i = nChunks - 1; i >= 0; i--) {
void* p = regions[i];
int res = munmap(p, chunkLen);
if (res != 0) {
printf("ERROR - munmap failed: %s\n", strerror(errno));
return 1;
}
}
printf("Big mmap succeeded\n");
return 0;
}