Current kernel (v3.10) or older has a problem on no resv mapping. If we map a region which is already reserved by other process, with MAP_NORESERVE flag, this mapping should be considered reserved maping, because allocated page will go into page cache and afterward it is treated as coming from reserved pool. This cause reserve count overflowed. To detect this kernel bug, add this test case.
Signed-off-by: Joonsoo Kim <iamjoonsoo....@lge.com> diff --git a/tests/Makefile b/tests/Makefile index 43afe5c..7a5126f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -13,7 +13,7 @@ LIB_TESTS = gethugepagesize test_root find_path unlinked_fd misalign \ shm-perms \ mremap-expand-slice-collision \ mremap-fixed-normal-near-huge mremap-fixed-huge-near-normal \ - corrupt-by-cow-opt noresv-preserve-resv-page + corrupt-by-cow-opt noresv-preserve-resv-page noresv-regarded-as-resv LIB_TESTS_64 = LIB_TESTS_64_STATIC = straddle_4GB huge_at_4GB_normal_below \ huge_below_4GB_normal_above diff --git a/tests/noresv-regarded-as-resv.c b/tests/noresv-regarded-as-resv.c new file mode 100644 index 0000000..4d5e5b7 --- /dev/null +++ b/tests/noresv-regarded-as-resv.c @@ -0,0 +1,77 @@ +/* + * libhugetlbfs - Easy use of Linux hugepages + * Copyright (C) 2013 Joonsoo Kim, LG Electronics. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> +#include <sys/mman.h> +#include <hugetlbfs.h> +#include "hugetests.h" + +#define P "noresv-regarded-as-resv" +#define DESC \ + "* Test to correct handling for reserve count. If no reserved *\n"\ + "* mapping is created to reserved file region, it should be *\n"\ + "* considered as reserve mapping. Otherwise, reserve count will be *\n"\ + "* overflowed. *\n" + +int main(int argc, char *argv[]) +{ + long hpage_size; + int nr_resvpages1, nr_resvpages2; + int fd; + char *p, *q; + + test_init(argc, argv); + + hpage_size = check_hugepagesize(); + nr_resvpages1 = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); + verbose_printf("Number of reserve page is %d\n", nr_resvpages1); + + fd = hugetlbfs_unlinked_fd(); + if (fd < 0) + FAIL("hugetlbfs_unlinked_fd()"); + + p = mmap(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (p == MAP_FAILED) + FAIL("mmap() 1: %s", strerror(errno)); + + verbose_printf("Reserve a page to file offset 0\n"); + + q = mmap(NULL, hpage_size, + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0); + if (q == MAP_FAILED) + FAIL("mmap() 2: %s", strerror(errno)); + + verbose_printf("Map a page of file offset 0 with no resv mapping\n"); + *q = 's'; + + munmap(p, hpage_size); + munmap(q, hpage_size); + close(fd); + verbose_printf("Unmap all mappings and close file\n"); + + nr_resvpages2 = get_huge_page_counter(hpage_size, HUGEPAGES_RSVD); + verbose_printf("Number of reserve page is now %d\n", nr_resvpages2); + + if (nr_resvpages1 != nr_resvpages2) + FAIL("Reserve count overflowed"); + + PASS(); +} diff --git a/tests/run_tests.py b/tests/run_tests.py index 98d233e..7b27c29 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -538,6 +538,7 @@ def functional_tests(): do_test_with_rlimit(resource.RLIMIT_STACK, -1, "stack_grow_into_huge") do_test("corrupt-by-cow-opt") do_test("noresv-preserve-resv-page") + do_test("noresv-regarded-as-resv") if dangerous == 1: do_test("readahead_reserve") -- 1.7.9.5 ------------------------------------------------------------------------------ Get your SQL database under version control now! Version control is standard for application code, but databases havent caught up. So what steps can you take to put your SQL databases under version control? Why should you start doing it? Read more to find out. http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel