userfaultfd() is here

I noticed a new (as of Linux kernel 4.3+) userfaultfd() system call while poking around make menuconfig today and, despite thinking that it may be complexity creep at first, found lots of good information about really interesting use-cases it enables.

The manpage is here, including a sample program, and gives a good idea about how userfaultfd() works.

To get more context and an overview of application ideas I recommend start with this presentation by Andrea Arcangeli.

To sum it up:

  • userfaultfd() is key to enabling live VM migrations and research-level stuff like memory externalization
  • memory constrained environments, like Android devices, need a way to reclaim memory from processes without crashing them.
    userfaultfd() makes it possible for the process to notice that its volatile pages are gone. It seems similar to how weak references work in many programming languages, but now with memory pages?
  • apparently more efficient snapshoting (think Redis), but I haven’t thought it through yet to understand how!

The presentation also mentions JIT improvements, but it’s a broader (and exciting) subject. This essay provides a deep look from the perspective of a LISP compiler/VM and touches upon the GC implications.

These awesome posts show how the HotSpot JVM currently uses memory protection/SIGSEGV:

More JVM Signal tricks – Thread control via mprotect
SIGSEGV as control flow – How the JVM optimizes your null checks

I wonder if userfaultfd() is coming to HotSpot?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s