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

后端 未结 7 1995
孤城傲影
孤城傲影 2020-12-02 13:29

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 th

7条回答
  •  执念已碎
    2020-12-02 13:40

    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).

提交回复
热议问题