From db2010da81211b3aa18a9395dd930f0d86fbffd5 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Thu, 2 Feb 2023 18:38:18 +0800 Subject: [PATCH] Add a new page fault test case page_fault4 It's like page_fault2 but the file read fault is triggered instead of file write fault. The improvement in file read fault path can be detected by this new test case. Signed-off-by: Yin Fengwei --- tests/page_fault4.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/page_fault4.c diff --git a/tests/page_fault4.c b/tests/page_fault4.c new file mode 100644 index 0000000..67cfd09 --- /dev/null +++ b/tests/page_fault4.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#define MEMSIZE (128 * 1024 * 1024) + +char *testcase_description = "Separate file private mapping page read fault"; + +void testcase(unsigned long long *iterations, unsigned long nr) +{ + char tmpfile[] = "/tmp/willitscale.XXXXXX"; + int fd = mkstemp(tmpfile); + unsigned long pgsize = getpagesize(); + + assert(fd >= 0); + assert(ftruncate(fd, MEMSIZE) == 0); + unlink(tmpfile); + + while (1) { + unsigned long i; + char cc __attribute__((unused)); + + char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fd, 0); + assert(c != MAP_FAILED); + + for (i = 0; i < MEMSIZE; i += pgsize) { + cc = *(volatile char *)(c + i); + (*iterations)++; + } + + munmap(c, MEMSIZE); + } +}