Skip to content
Advertisement

Can I tell Linux not to swap out a particular processes’ memory?

Is there a way to tell Linux that it shouldn’t swap out a particular processes’ memory to disk?

Its a Java app, so ideally I’m hoping for a way to do this from the command line.

I’m aware that you can set the global swappiness to 0, but is this wise?

Advertisement

Answer

You can do this via the mlockall(2) system call under Linux; this will work for the whole process, but do read about the argument you need to pass.

Do you really need to pull the whole thing in-core? If it’s a java app, you would presumably lock the whole JVM in-core. I don’t know of a command-line method for doing this, but you could write a trivial program to call fork, call mlockall, then exec.

You might also look to see if one of the access pattern notifications in madvise(2) meets your needs. Advising the VM subsystem about a better paging strategy might work out better if it’s applicable for you.

Note that a long time ago now under SunOS, there was a mechanism similar to madvise called vadvise(2).

Advertisement