5

I want to keep a process in RAM. It should never go into swap. Is this possible?

The process is a Java program. I'm running CentoS 7.

  • 1
    While definitely related, this question is not an "exact duplicate" of http://unix.stackexchange.com/questions/77939/turning-off-swapping-for-only-one-process-with-cgroups . The other question explicitly request cgroups to be used to keep the process in RAM. One significant issue with cgroups is they cannot guarantee the process will stay in RAM. It is a best effort solution. On the other hand, using mlockall will guarantee all pages stay in RAM, and if undoable, the process has the choice to stop. Both approaches have their pros and cons. – jlliagre Apr 21 '16 at 23:23
  • i used to use memlockd for this, but haven't needed to for some time. no idea if it still works with modern kernels and systemd and/or cgroups. probably does, the author uses systemd. if you can't find it anywhere else (or packaged for your distro), it's at https://packages.debian.org/sid/admin/memlockd – cas Apr 22 '16 at 04:01

1 Answers1

3

mlockall() is a standard C function that locks all of a currently mapped process memory to RAM.

One simple way to use it from a JVM is to call it through JNA (Java Native Access). This is what does the mlockall agent available here.

jlliagre
  • 61,204