| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <stdlib.h> |
| 22 |
#include <string.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <sys/mman.h> |
| 25 |
|
| 26 |
#include "hugetests.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#define MIN_PAGE_SIZE 65536 |
| 35 |
|
| 36 |
static int block_sizes[] = { |
| 37 |
sizeof(int), 1024, 128*1024, 1024*1024, 16*1024*1024, |
| 38 |
32*1024*1024, |
| 39 |
}; |
| 40 |
#define NUM_SIZES (sizeof(block_sizes) / sizeof(block_sizes[0])) |
| 41 |
|
| 42 |
int main(int argc, char *argv[]) |
| 43 |
{ |
| 44 |
int i; |
| 45 |
char *env1, *env2, *exe; |
| 46 |
int expect_hugepage = 0; |
| 47 |
char *p; |
| 48 |
|
| 49 |
test_init(argc, argv); |
| 50 |
exe = strrchr(test_name, '/'); |
| 51 |
if (exe) |
| 52 |
exe++; |
| 53 |
else |
| 54 |
exe = test_name; |
| 55 |
|
| 56 |
env1 = getenv("HUGETLB_MORECORE"); |
| 57 |
verbose_printf("HUGETLB_MORECORE=%s\n", env1); |
| 58 |
env2 = getenv("HUGETLB_RESTRICT_EXE"); |
| 59 |
verbose_printf("HUGETLB_RESTRICT_EXE=%s\n", env2); |
| 60 |
if (env1 && (!env2 || strstr(env2, exe))) |
| 61 |
expect_hugepage = 1; |
| 62 |
verbose_printf("expect_hugepage=%d\n", expect_hugepage); |
| 63 |
|
| 64 |
for (i = 0; i < NUM_SIZES; i++) { |
| 65 |
int size = block_sizes[i]; |
| 66 |
unsigned long long mapping_size; |
| 67 |
|
| 68 |
p = malloc(size); |
| 69 |
if (! p) |
| 70 |
FAIL("malloc()"); |
| 71 |
|
| 72 |
verbose_printf("malloc(%d) = %p\n", size, p); |
| 73 |
|
| 74 |
memset(p, 0, size); |
| 75 |
|
| 76 |
mapping_size = get_mapping_page_size(p); |
| 77 |
|
| 78 |
if (expect_hugepage && (mapping_size <= MIN_PAGE_SIZE)) |
| 79 |
FAIL("Address is not hugepage"); |
| 80 |
if (!expect_hugepage && (mapping_size > MIN_PAGE_SIZE)) |
| 81 |
FAIL("Address is unexpectedly huge"); |
| 82 |
|
| 83 |
free(p); |
| 84 |
} |
| 85 |
|
| 86 |
PASS(); |
| 87 |
} |