Skip to contentSkip to conversation

selftests/vm: Add tests to validate mirror functionality with mremap

PATCH Superseded Anshuman Khandual 2 participants 4 messages Jul 25, 2017 – Jul 26, 2017

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/vm: Add tests to validate mirror functionality with mremap

This adds two tests to validate mirror functionality with mremap() system call on shared and private anon mappings.

---
Changes in V2:

- Added a test for private anon mappings
- Used sysconf(_SC_PAGESIZE) instead of hard coding page size
- Used MREMAP_MAYMOVE instead of hard coding the flag value 1

 tools/testing/selftests/vm/Makefile                |  2 +
 .../selftests/vm/mremap_mirror_private_anon.c      | 49 ++++++++++++++++++
 .../selftests/vm/mremap_mirror_shared_anon.c       | 58 ++++++++++++++++++++++
 3 files changed, 109 insertions(+)
 create mode 100644 tools/testing/selftests/vm/mremap_mirror_private_anon.c
 create mode 100644 tools/testing/selftests/vm/mremap_mirror_shared_anon.c
tools/testing/selftests/vm/Makefile +2 -0
index cbb29e4..6401f91 100644
@@ -17,6 +17,8 @@ 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_GEN_FILES += mremap_mirror_private_anon
 
 TEST_PROGS := run_vmtests
 
tools/testing/selftests/vm/mremap_mirror_private_anon.c new file +49 -0

49 lines not on this page · raw message

tools/testing/selftests/vm/mremap_mirror_shared_anon.c new file +58 -0

58 lines not on this page · raw message

Signature · 7 lines
1.8.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

On Tue 25-07-17 12:06:57, Anshuman Khandual wrote:
[...]

Quoted 1 line
tools/testing/selftests/vm/mremap_mirror_private_anon.c +0 -0

[...]

tools/testing/selftests/vm/mremap_mirror_private_anon.c line 40

Quoted 13 lines
tools/testing/selftests/vm/mremap_mirror_private_anon.c +13 -0
+	ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | 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, MREMAP_MAYMOVE);
+	if (mirror_ptr == MAP_FAILED) {
+		perror("mremap() failed");
+		return -1;
+	}

What is the point of this test? It will break with Mike's patch very soon. Btw. it never worked.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 4 lines · Michal Hocko

On Tue 25-07-17 12:06:57, Anshuman Khandual wrote:
[...]

Quoted 1 line
tools/testing/selftests/vm/mremap_mirror_private_anon.c +0 -0

[...]

Quoted 16 lines

tools/testing/selftests/vm/mremap_mirror_private_anon.c line 40

Quoted 13 lines
tools/testing/selftests/vm/mremap_mirror_private_anon.c +13 -0
+	ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | 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, MREMAP_MAYMOVE);
+	if (mirror_ptr == MAP_FAILED) {
+		perror("mremap() failed");
+		return -1;
+	}

What is the point of this test? It will break with Mike's patch very soon. Btw. it never worked.

It works now. The new 'mirrored' buffer does not have same elements as that of the original one. Yes, once Mike's patch is merged, it will fail during the mremap() call itself IIUC. I can change this test to verify that mremap() call failure then but now the mismatch of elements between the buffers is what is expected and is happening.

But if you would like I can change the test to check for mremap() failure in this case (which will fail in the current mainline but will pass eventually when Mike's patch is in). Please do suggest.

#3 lore raw
Quoted 22 lines · Anshuman Khandual
Quoted 4 lines · Michal Hocko

On Tue 25-07-17 12:06:57, Anshuman Khandual wrote:
[...]

Quoted 1 line
tools/testing/selftests/vm/mremap_mirror_private_anon.c +0 -0

[...]

Quoted 16 lines

tools/testing/selftests/vm/mremap_mirror_private_anon.c line 40

Quoted 13 lines
tools/testing/selftests/vm/mremap_mirror_private_anon.c +13 -0
+	ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | 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, MREMAP_MAYMOVE);
+	if (mirror_ptr == MAP_FAILED) {
+		perror("mremap() failed");
+		return -1;
+	}

What is the point of this test? It will break with Mike's patch very soon. Btw. it never worked.

Quoted 2 lines

It works now. The new 'mirrored' buffer does not have same elements as that of the original one.

So what exactly are you testing here? The current implementation or the semantic of mremap. Because having a different content after mremap doesn't make _any_ sense to me. I might be misreading the intention of the syscall but to me it sounds like the content should be same as the original one... If my reading is wrong then -EINVAL for anon mremaps is simply wrong.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>