From: Mike Rapoport <rppt@linux.vnet.ibm.com>
To: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>,
Pavel Emelyanov <xemul@virtuozzo.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Mike Rapoport <rppt@linux.vnet.ibm.com>
Subject: [PATCH 7/7] userfaultfd: shmem: add userfaultfd_shmem test
Date: Thu, 4 Aug 2016 11:14:18 +0300 [thread overview]
Message-ID: <1470298458-9925-8-git-send-email-rppt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1470298458-9925-1-git-send-email-rppt@linux.vnet.ibm.com>
The test verifies that anonymous shared mapping can be used with userfault
using the existing testing method.
The shared memory area is allocated using mmap(..., MAP_SHARED |
MAP_ANONYMOUS, ...) and released using madvise(MADV_REMOVE)
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
tools/testing/selftests/vm/Makefile | 3 +++
tools/testing/selftests/vm/run_vmtests | 11 ++++++++++
tools/testing/selftests/vm/userfaultfd.c | 37 ++++++++++++++++++++++++++++++--
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index aaa4225..12ff211 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -11,6 +11,7 @@ BINARIES += thuge-gen
BINARIES += transhuge-stress
BINARIES += userfaultfd
BINARIES += userfaultfd_hugetlb
+BINARIES += userfaultfd_shmem
all: $(BINARIES)
%: %.c
@@ -19,6 +20,8 @@ userfaultfd: userfaultfd.c ../../../../usr/include/linux/kernel.h
$(CC) $(CFLAGS) -O2 -o $@ $< -lpthread
userfaultfd_hugetlb: userfaultfd.c ../../../../usr/include/linux/kernel.h
$(CC) $(CFLAGS) -DHUGETLB_TEST -O2 -o $@ $< -lpthread
+userfaultfd_shmem: userfaultfd.c ../../../../usr/include/linux/kernel.h
+ $(CC) $(CFLAGS) -DSHMEM_TEST -O2 -o $@ $< -lpthread
../../../../usr/include/linux/kernel.h:
make -C ../../../.. headers_install
diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests
index 14d697e..c92f6cf 100755
--- a/tools/testing/selftests/vm/run_vmtests
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -116,6 +116,17 @@ else
fi
rm -f $mnt/ufd_test_file
+echo "----------------------------"
+echo "running userfaultfd_shmem"
+echo "----------------------------"
+./userfaultfd_shmem 128 32
+if [ $? -ne 0 ]; then
+ echo "[FAIL]"
+ exitcode=1
+else
+ echo "[PASS]"
+fi
+
#cleanup
umount $mnt
rm -rf $mnt
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index d753a91..a5e5808 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -101,8 +101,9 @@ pthread_attr_t attr;
~(unsigned long)(sizeof(unsigned long long) \
- 1)))
-#ifndef HUGETLB_TEST
+#if !defined(HUGETLB_TEST) && !defined(SHMEM_TEST)
+/* Anonymous memory */
#define EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \
(1 << _UFFDIO_COPY) | \
(1 << _UFFDIO_ZEROPAGE))
@@ -127,10 +128,13 @@ static void allocate_area(void **alloc_area)
}
}
-#else /* HUGETLB_TEST */
+#else /* HUGETLB_TEST or SHMEM_TEST */
#define EXPECTED_IOCTLS UFFD_API_RANGE_IOCTLS_BASIC
+#ifdef HUGETLB_TEST
+
+/* HugeTLB memory */
static int release_pages(char *rel_area)
{
int ret = 0;
@@ -162,8 +166,37 @@ static void allocate_area(void **alloc_area)
huge_fd_off0 = *alloc_area;
}
+#elif defined(SHMEM_TEST)
+
+/* Shared memory */
+static int release_pages(char *rel_area)
+{
+ int ret = 0;
+
+ if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) {
+ perror("madvise");
+ ret = 1;
+ }
+
+ return ret;
+}
+
+static void allocate_area(void **alloc_area)
+{
+ *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+ if (*alloc_area == MAP_FAILED) {
+ fprintf(stderr, "shared memory mmap failed\n");
+ *alloc_area = NULL;
+ }
+}
+
+#else /* SHMEM_TEST */
+#error "Undefined test type"
#endif /* HUGETLB_TEST */
+#endif /* !defined(HUGETLB_TEST) && !defined(SHMEM_TEST) */
+
static int my_bcmp(char *str1, char *str2, size_t n)
{
unsigned long i;
--
1.9.1
--
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 prev parent reply other threads:[~2016-08-04 8:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-04 8:14 [PATCH 0/7] userfaultfd: add support for shared memory Mike Rapoport
2016-08-04 8:14 ` [PATCH 1/7] userfaultfd: introduce vma_can_userfault Mike Rapoport
2016-08-04 8:14 ` [PATCH 2/7] userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support Mike Rapoport
2016-08-04 8:14 ` [PATCH 3/7] userfaultfd: shmem: introduce vma_is_shmem Mike Rapoport
2016-08-04 8:14 ` [PATCH 4/7] userfaultfd: shmem: use shmem_mcopy_atomic_pte for shared memory Mike Rapoport
2016-08-04 8:14 ` [PATCH 5/7] userfaultfd: shmem: add userfaultfd hook for shared memory faults Mike Rapoport
2016-08-04 8:14 ` [PATCH 6/7] userfaultfd: shmem: allow registration of shared memory ranges Mike Rapoport
2016-08-04 8:14 ` Mike Rapoport [this message]
2016-08-04 18:54 ` [PATCH 0/7] userfaultfd: add support for shared memory Andrea Arcangeli
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=1470298458-9925-8-git-send-email-rppt@linux.vnet.ibm.com \
--to=rppt@linux.vnet.ibm.com \
--cc=aarcange@redhat.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xemul@virtuozzo.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