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 unix.stackexchange.com/questions/77939/… . 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 packages.debian.org/sid/admin/memlockd – cas Apr 22 '16 at 4:01
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.