Debian Codegraph @

tests/noresv-regarded-as-resv.c

raw symbols SCIP
1 /*
2 * libhugetlbfs - Easy use of Linux hugepages
3 * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 }