Re: [PATCH v4] mm: Add MREMAP_DONTUNMAP to mremap().
From: Daniel Colascione <hidden>
Date: 2020-02-11 23:53:44
Also in:
linux-mm, lkml
On Tue, Feb 11, 2020 at 3:32 PM Brian Geffon [off-list ref] wrote:
Hi Daniel,quoted
What about making the left-behind mapping PROT_NONE? This way, we'll still solve the address-space race in Lokesh's use case (because even a PROT_NONE mapping reserves address space) but won't incur any additional commit until someone calls mprotect(PROT_WRITE) on the left-behind mapping.This limits the usefulness of the feature IMO and really is too specific to that one use case, suppose you want to snapshot a memory region to disk without having to stop a thread you can mremap(MREMAP_DONTUNMAP) it to another location and safely write it to disk knowing the faulting thread will be stopped and you can handle it later if it was registered with userfaultfd, if we were to also change it to PROT_NONE that thread would see a SEGV. There are other examples where you can possibly use this flag instead of VM_UFFD_WP, but changing the protections of the mapping prevents you from being able to do this without a funny signal handler dance.
We seem to have identified two use cases which require contradictory things. We can handle this with an option. Maybe the new region's protection bits should be specified in the flags argument. The most general API would accept any set of mmap flags to apply to the left-behind region, but it's probably hard to squeeze that functionality into the existing API.