1#include <stdio.h>
2#include <sys/mman.h>
3#include <unistd.h>
4
5#include "utils.h"
6
7
8#define SIZE (16 * 1024 * 1024)
9
10static int test_body(void)
11{
12 void *addr;
13 char *p;
14
15 addr = (void *)0xa0000000;
16
17 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
18 MAP_HUGETLB | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
19 if (p != MAP_FAILED) {
20
21
22
23
24
25
26
27 if (munmap(addr, SIZE)) {
28 perror("munmap");
29 return 1;
30 }
31 }
32
33 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
34 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
35 if (p == MAP_FAILED) {
36 printf("Mapping failed @ %p\n", addr);
37 perror("mmap");
38 return 1;
39 }
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 *p = 0xf;
55
56 munmap(addr, SIZE);
57
58 return 0;
59}
60
61static int test_main(void)
62{
63 int i;
64
65
66 for (i = 0; i < 10000; i++)
67 if (test_body())
68 return 1;
69
70 return 0;
71}
72
73int main(void)
74{
75 return test_harness(test_main, "hugetlb_vs_thp");
76}
77