| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#define _GNU_SOURCE |
| 20 |
#include <fcntl.h> |
| 21 |
#include <stdio.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <errno.h> |
| 25 |
#include <unistd.h> |
| 26 |
#include <sys/mman.h> |
| 27 |
|
| 28 |
#include <hugetlbfs.h> |
| 29 |
#include "hugetests.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
int main(int argc, char *argv[]) |
| 42 |
{ |
| 43 |
long hpage_size; |
| 44 |
int fd; |
| 45 |
void *p; |
| 46 |
unsigned long initial_rsvd, map_rsvd, readahead_rsvd, end_rsvd; |
| 47 |
|
| 48 |
test_init(argc, argv); |
| 49 |
|
| 50 |
|
| 51 |
hpage_size = check_hugepagesize(); |
| 52 |
fd = hugetlbfs_unlinked_fd(); |
| 53 |
if (fd < 0) |
| 54 |
FAIL("hugetlbfs_unlinked_fd()"); |
| 55 |
initial_rsvd = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); |
| 56 |
verbose_printf("Reserve count before map: %lu\n", initial_rsvd); |
| 57 |
|
| 58 |
|
| 59 |
p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 60 |
fd, 0); |
| 61 |
if (p == MAP_FAILED) |
| 62 |
FAIL("mmap(): %s", strerror(errno)); |
| 63 |
map_rsvd = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); |
| 64 |
verbose_printf("Reserve count after map: %lu\n", map_rsvd); |
| 65 |
|
| 66 |
|
| 67 |
readahead(fd, 0, hpage_size); |
| 68 |
readahead_rsvd = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); |
| 69 |
verbose_printf("Reserve count after readahead: %lu\n", readahead_rsvd); |
| 70 |
|
| 71 |
|
| 72 |
memset(p, 1, hpage_size); |
| 73 |
|
| 74 |
|
| 75 |
munmap(p, hpage_size); |
| 76 |
close(fd); |
| 77 |
end_rsvd = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); |
| 78 |
verbose_printf("Reserve count after close(): %lu\n", end_rsvd); |
| 79 |
|
| 80 |
|
| 81 |
if (end_rsvd != initial_rsvd) |
| 82 |
FAIL("Reserve leaked: %lu != %lu\n", end_rsvd, initial_rsvd); |
| 83 |
|
| 84 |
PASS(); |
| 85 |
} |