From: Anshuman Khandual <khandual@linux.vnet.ibm.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, mike.kravetz@oracle.com
Subject: [PATCH] selftests/vm: Add test to validate mirror functionality with mremap
Date: Thu, 20 Jul 2017 15:06:51 +0530 [thread overview]
Message-ID: <20170720093651.22106-1-khandual@linux.vnet.ibm.com> (raw)
This adds a test to validate mirror functionality with mremap()
system call on shared anon mappings.
Suggested-by: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
---
tools/testing/selftests/vm/Makefile | 1 +
.../selftests/vm/mremap_mirror_shared_anon.c | 54 ++++++++++++++++++++++
2 files changed, 55 insertions(+)
create mode 100644 tools/testing/selftests/vm/mremap_mirror_shared_anon.c
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index cbb29e4..11657ff5 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -17,6 +17,7 @@ TEST_GEN_FILES += transhuge-stress
TEST_GEN_FILES += userfaultfd
TEST_GEN_FILES += mlock-random-test
TEST_GEN_FILES += virtual_address_range
+TEST_GEN_FILES += mremap_mirror_shared_anon
TEST_PROGS := run_vmtests
diff --git a/tools/testing/selftests/vm/mremap_mirror_shared_anon.c b/tools/testing/selftests/vm/mremap_mirror_shared_anon.c
new file mode 100644
index 0000000..b0adbb2
--- /dev/null
+++ b/tools/testing/selftests/vm/mremap_mirror_shared_anon.c
@@ -0,0 +1,54 @@
+/*
+ * Test to verify mirror functionality with mremap() system
+ * call for shared anon mappings.
+ *
+ * Copyright (C) 2017 Anshuman Khandual, IBM Corporation
+ *
+ * Licensed under GPL V2
+ */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+
+#define PATTERN 0xbe
+#define ALLOC_SIZE 0x10000UL /* Works for 64K and 4K pages */
+
+int test_mirror(char *old, char *new, unsigned long size)
+{
+ unsigned long i;
+
+ for (i = 0; i < size; i++) {
+ if (new[i] != old[i]) {
+ printf("Mismatch at new[%lu] expected "
+ "%d received %d\n", i, old[i], new[i]);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ char *ptr, *mirror_ptr;
+
+ ptr = mmap(NULL, ALLOC_SIZE, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ if (ptr == MAP_FAILED) {
+ perror("map() failed");
+ return -1;
+ }
+ memset(ptr, PATTERN, ALLOC_SIZE);
+
+ mirror_ptr = (char *) mremap(ptr, 0, ALLOC_SIZE, 1);
+ if (mirror_ptr == MAP_FAILED) {
+ perror("mremap() failed");
+ return -1;
+ }
+
+ if (test_mirror(ptr, mirror_ptr, ALLOC_SIZE))
+ return 1;
+ return 0;
+}
--
1.8.5.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2017-07-20 9:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 9:36 Anshuman Khandual [this message]
2017-07-20 23:19 ` [PATCH] selftests/vm: Add test to validate mirror functionality with mremap Mike Kravetz
2017-07-21 10:38 ` Anshuman Khandual
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170720093651.22106-1-khandual@linux.vnet.ibm.com \
--to=khandual@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).