| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
#include <stdlib.h> |
| 21 |
#include <unistd.h> |
| 22 |
#include <signal.h> |
| 23 |
#include <sys/mman.h> |
| 24 |
#include <hugetlbfs.h> |
| 25 |
#include "hugetests.h" |
| 26 |
|
| 27 |
#define P "noresv-regarded-as-resv" |
| 28 |
#define DESC \ |
| 29 |
"* Test to correct handling for reserve count. If no reserved *\n"\ |
| 30 |
"* mapping is created to reserved file region, it should be *\n"\ |
| 31 |
"* considered as reserve mapping. Otherwise, reserve count will be *\n"\ |
| 32 |
"* overflowed. *\n" |
| 33 |
|
| 34 |
int main(int argc, char *argv[]) |
| 35 |
{ |
| 36 |
long hpage_size; |
| 37 |
int nr_resvpages1, nr_resvpages2; |
| 38 |
int fd; |
| 39 |
char *p, *q; |
| 40 |
|
| 41 |
test_init(argc, argv); |
| 42 |
|
| 43 |
hpage_size = check_hugepagesize(); |
| 44 |
nr_resvpages1 = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); |
| 45 |
verbose_printf("Number of reserve page is %d\n", nr_resvpages1); |
| 46 |
|
| 47 |
fd = hugetlbfs_unlinked_fd(); |
| 48 |
if (fd < 0) |
| 49 |
FAIL("hugetlbfs_unlinked_fd()"); |
| 50 |
|
| 51 |
p = mmap(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 52 |
if (p == MAP_FAILED) |
| 53 |
FAIL("mmap() 1: %s", strerror(errno)); |
| 54 |
|
| 55 |
verbose_printf("Reserve a page to file offset 0\n"); |
| 56 |
|
| 57 |
q = mmap(NULL, hpage_size, |
| 58 |
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0); |
| 59 |
if (q == MAP_FAILED) |
| 60 |
FAIL("mmap() 2: %s", strerror(errno)); |
| 61 |
|
| 62 |
verbose_printf("Map a page of file offset 0 with no resv mapping\n"); |
| 63 |
*q = 's'; |
| 64 |
|
| 65 |
munmap(p, hpage_size); |
| 66 |
munmap(q, hpage_size); |
| 67 |
close(fd); |
| 68 |
verbose_printf("Unmap all mappings and close file\n"); |
| 69 |
|
| 70 |
nr_resvpages2 = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); |
| 71 |
verbose_printf("Number of reserve page is now %d\n", nr_resvpages2); |
| 72 |
|
| 73 |
if (nr_resvpages1 != nr_resvpages2) |
| 74 |
FAIL("Reserve count overflowed"); |
| 75 |
|
| 76 |
PASS(); |
| 77 |
} |