mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
![Brian Geffon](/assets/img/avatar_default.png)
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." [bgeffon@google.com: v6] Link: http://lkml.kernel.org/r/20200218173221.237674-1-bgeffon@google.com [bgeffon@google.com: v7] Link: http://lkml.kernel.org/r/20200221174248.244748-1-bgeffon@google.com Signed-off-by: Brian Geffon <bgeffon@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Tested-by: Lokesh Gidra <lokeshgidra@google.com> Reviewed-by: Minchan Kim <minchan@kernel.org> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: "Michael S . Tsirkin" <mst@redhat.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Will Deacon <will@kernel.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Sonny Rao <sonnyrao@google.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Joel Fernandes <joel@joelfernandes.org> Cc: Yu Zhao <yuzhao@google.com> Cc: Jesse Barnes <jsbarnes@google.com> Cc: Nathan Chancellor <natechancellor@gmail.com> Cc: Florian Weimer <fweimer@redhat.com> Link: http://lkml.kernel.org/r/20200207201856.46070-1-bgeffon@google.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
43 lines
1.5 KiB
C
43 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
|
#ifndef _UAPI_LINUX_MMAN_H
|
|
#define _UAPI_LINUX_MMAN_H
|
|
|
|
#include <asm/mman.h>
|
|
#include <asm-generic/hugetlb_encode.h>
|
|
|
|
#define MREMAP_MAYMOVE 1
|
|
#define MREMAP_FIXED 2
|
|
#define MREMAP_DONTUNMAP 4
|
|
|
|
#define OVERCOMMIT_GUESS 0
|
|
#define OVERCOMMIT_ALWAYS 1
|
|
#define OVERCOMMIT_NEVER 2
|
|
|
|
#define MAP_SHARED 0x01 /* Share changes */
|
|
#define MAP_PRIVATE 0x02 /* Changes are private */
|
|
#define MAP_SHARED_VALIDATE 0x03 /* share + validate extension flags */
|
|
|
|
/*
|
|
* Huge page size encoding when MAP_HUGETLB is specified, and a huge page
|
|
* size other than the default is desired. See hugetlb_encode.h.
|
|
* All known huge page size encodings are provided here. It is the
|
|
* responsibility of the application to know which sizes are supported on
|
|
* the running system. See mmap(2) man page for details.
|
|
*/
|
|
#define MAP_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
|
|
#define MAP_HUGE_MASK HUGETLB_FLAG_ENCODE_MASK
|
|
|
|
#define MAP_HUGE_64KB HUGETLB_FLAG_ENCODE_64KB
|
|
#define MAP_HUGE_512KB HUGETLB_FLAG_ENCODE_512KB
|
|
#define MAP_HUGE_1MB HUGETLB_FLAG_ENCODE_1MB
|
|
#define MAP_HUGE_2MB HUGETLB_FLAG_ENCODE_2MB
|
|
#define MAP_HUGE_8MB HUGETLB_FLAG_ENCODE_8MB
|
|
#define MAP_HUGE_16MB HUGETLB_FLAG_ENCODE_16MB
|
|
#define MAP_HUGE_32MB HUGETLB_FLAG_ENCODE_32MB
|
|
#define MAP_HUGE_256MB HUGETLB_FLAG_ENCODE_256MB
|
|
#define MAP_HUGE_512MB HUGETLB_FLAG_ENCODE_512MB
|
|
#define MAP_HUGE_1GB HUGETLB_FLAG_ENCODE_1GB
|
|
#define MAP_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB
|
|
#define MAP_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB
|
|
|
|
#endif /* _UAPI_LINUX_MMAN_H */
|