我可以告诉Linux不要换出特定进程的内存吗? [英] Can I tell Linux not to swap out a particular processes' memory?
问题描述
有没有办法告诉Linux,它不应该将特定进程的内存换出到磁盘上?
Is there a way to tell Linux that it shouldn't swap out a particular processes' memory to disk?
它是一个Java应用程序,因此理想情况下,我希望从命令行中执行此操作.
Its a Java app, so ideally I'm hoping for a way to do this from the command line.
我知道您可以将全局swappiness设置为0,但这是明智的吗?
I'm aware that you can set the global swappiness to 0, but is this wise?
推荐答案
您可以通过 mlockall(2)系统调用;这将适用于整个过程,但请务必阅读您需要传递的参数.
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.
您真的需要将所有内容都放入核心吗?如果它是一个Java应用程序,则可能会将整个JVM锁定在内核中.我不知道执行此操作的命令行方法,但是您可以编写一个简单的程序来依次调用fork
,先调用mlockall
然后再调用exec
.
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
.
您还可能希望查看 madvise(2)满足您的需求.如果VM子系统适合您,则向其建议有关更好的分页策略的建议可能会更好.
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.
请注意,很久以前,在SunOS下,存在一种类似于madvise的机制,称为
Note that a long time ago now under SunOS, there was a mechanism similar to madvise called vadvise(2).
这篇关于我可以告诉Linux不要换出特定进程的内存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!