linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Lokesh Gidra <lokeshgidra@google.com>, Brian Geffon <bgeffon@google.com>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org,
	Sonny Rao <sonnyrao@google.com>,
	Jesse Barnes <jsbarnes@google.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Minchan Kim <minchan@kernel.org>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH v2] mremap.2: Add information for MREMAP_DONTUNMAP.
Date: Wed, 22 Apr 2020 14:08:02 +0200	[thread overview]
Message-ID: <f7592167-06d5-5f81-9d9e-07afd6704e31@gmail.com> (raw)
In-Reply-To: <CA+EESO6ODSQV4QA0-ZpyvmHb2395Gutt0ac5uBYNyTdWKdSY1Q@mail.gmail.com>

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/

  reply	other threads:[~2020-04-22 12:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15 16:49 [PATCH v2] mremap.2: Add information for MREMAP_DONTUNMAP Brian Geffon
2020-04-16  7:07 ` Michael Kerrisk (man-pages)
2020-04-17  3:01   ` Brian Geffon
2020-04-22  0:15     ` Lokesh Gidra
2020-04-22 12:08       ` Michael Kerrisk (man-pages) [this message]
2020-04-22 12:05     ` Michael Kerrisk (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7592167-06d5-5f81-9d9e-07afd6704e31@gmail.com \
    --to=mtk.manpages@gmail.com \
    --cc=bgeffon@google.com \
    --cc=jsbarnes@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-man@vger.kernel.org \
    --cc=lokeshgidra@google.com \
    --cc=minchan@kernel.org \
    --cc=sonnyrao@google.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).