Skip to contentSkip to conversation

mm-add-mremap_dontunmap-to-mremap.patch removed from -mm tree

merged [email protected] 1 participant 1 message Apr 3, 2020

lore
Share & tools
lore

[email protected]

author tree notice Applied
#0 lore raw

The patch titled
Subject: mm/mremap: add MREMAP_DONTUNMAP to mremap()
has been removed from the -mm tree. Its filename was
mm-add-mremap_dontunmap-to-mremap.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Brian Geffon <[email protected]>
Subject: mm/mremap: add MREMAP_DONTUNMAP to mremap()

When remapping an anonymous, private mapping, if MREMAP_DONTUNMAP is set, the source mapping will not be removed. The remap operation will be performed as it would have been normally by moving over the page tables to the new mapping. The old vma will have any locked flags cleared, have no pagetables, and any userfaultfds that were watching that range will continue watching it.

For a mapping that is shared or not anonymous, MREMAP_DONTUNMAP will cause the mremap() call to fail. Because MREMAP_DONTUNMAP always results in moving a VMA you MUST use the MREMAP_MAYMOVE flag, it's not possible to resize a VMA while also moving with MREMAP_DONTUNMAP so old_len must always be equal to the new_len otherwise it will return -EINVAL.

We hope to use this in Chrome OS where with userfaultfd we could write an anonymous mapping to disk without having to STOP the process or worry about VMA permission changes.

This feature also has a use case in Android, Lokesh Gidra has said that "As part of using userfaultfd for GC, We'll have to move the physical pages of the java heap to a separate location. For this purpose mremap will be used. Without the MREMAP_DONTUNMAP flag, when I mremap the java heap, its virtual mapping will be removed as well. Therefore, we'll require performing mmap immediately after. This is not only time consuming but also opens a time window where a native thread may call mmap and reserve the java heap's address range for its own usage. This flag solves the problem."

---

 include/uapi/linux/mman.h |    5 +-
 mm/mremap.c               |   90 +++++++++++++++++++++++++++---------
 2 files changed, 72 insertions(+), 23 deletions(-)
include/uapi/linux/mman.h renamed from include/uapi/linux/mman.h~mm-add-mremap_dontunmap-to-mremap +3 -2
@@ -5,8 +5,9 @@
 #include <asm/mman.h>
 #include <asm-generic/hugetlb_encode.h>
 
-#define MREMAP_MAYMOVE	1
-#define MREMAP_FIXED	2
+#define MREMAP_MAYMOVE		1
+#define MREMAP_FIXED		2
+#define MREMAP_DONTUNMAP	4
 
 #define OVERCOMMIT_GUESS		0
 #define OVERCOMMIT_ALWAYS		1
mm/mremap.c renamed from mm/mremap.c~mm-add-mremap_dontunmap-to-mremap +69 -21

191 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are