]> Git Repo - linux.git/commit
mm/mremap: add MREMAP_DONTUNMAP to mremap()
authorBrian Geffon <[email protected]>
Thu, 2 Apr 2020 04:09:17 +0000 (21:09 -0700)
committerLinus Torvalds <[email protected]>
Thu, 2 Apr 2020 16:35:30 +0000 (09:35 -0700)
commite346b3813067d4b17383f975f197a9aa28a3b077
tree677cade6d512430341c84900a63547d1ade923b4
parentdf529cabb7a2553bbeb7bab725776f62fdcec972
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."

[[email protected]: v6]
Link: http://lkml.kernel.org/r/[email protected]
[[email protected]: v7]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Brian Geffon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Tested-by: Lokesh Gidra <[email protected]>
Reviewed-by: Minchan Kim <[email protected]>
Acked-by: Kirill A. Shutemov <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: "Michael S . Tsirkin" <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Sonny Rao <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Joel Fernandes <[email protected]>
Cc: Yu Zhao <[email protected]>
Cc: Jesse Barnes <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Florian Weimer <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
include/uapi/linux/mman.h
mm/mremap.c
This page took 0.049072 seconds and 4 git commands to generate.