Hello Brian and Loresh, >>>> +Possible applications for this behavior might be garbage collection or >>> >>> Can you elaborate the garbage collection use case a little, please? >> >> Lokesh, who is CCed, can probably expand better than I can, Lokesh >> would you mind elaborating on how the JVM plans to use this. >> > There are many GC algorithms in literature which use PROT_NONE+SIGSEGV > trick to implement concurrent compaction of java heap. In Android > Runtime we plan to use userfaultfd instead. But this requires a > stop-the-world, wherein Java threads are paused, right before starting > the compaction phase. Within this pause, the physical pages in the > Java heap will be moved to another area, so that the Java heap, which > is already registered with userfaultfd, can start 'userfaulting' (as > Java heap pages are missing) once application threads are resumed. > > In the absence of MREMAP_DONTUNMAP, I'd have to do it by first doing > mremap, and then mmaping Java heap, as its virtual mapping would be > removed by the preceding mremap. This not only causes performance > issues as two system calls need to be made instead of one, but it also > leaves a window open for a native thread, which is not paused, to > create a virtual mapping for its own usage right where Java heap is > supposed to be. Thank you both for your explanations. I added some text to the page. Does the following look okay? MREMAP_DONTUNMAP use cases Possible applications for MREMAP_DONTUNMAP include: * Non-cooperative userfaultfd(2): an application can yank out a virtual address range using MREMAP_DONTUNMAP and then employ a userfaultfd(2) handler to handle the page faults that subse‐ quently occur as other threads in the process touch pages in the yanked range. * Garbage collection: MREMAP_DONTUNMAP can be used in conjunction with userfaultfd(2) to implement garbage collection algorithms (e.g., in a Java virtual machine). Such an implementation can be cheaper (and simpler) than conventional garbage collection techniques that involve marking pages with protection PROT_NONE in conjunction with the of a SIGSEGV handler to catch accesses to those pages. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/