bash 强制进程完全在交换中运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17122446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:42:03  来源:igfitidea点击:

Force process to run in swap completely

linuxbashprocessswap

提问by Mikopet

I didn't find the solution for that, so I'm not sure, is there any.

我没有找到解决方案,所以我不确定,有没有。

I have a VPS, with 512MB RAM, and with SSD disks.

我有一个 VPS,有 512MB RAM 和 SSD 磁盘。

My problem is: I want to run a java based server program, and I want it to take in swap completely. The -Xms for it now 384, but it's not enough.

我的问题是:我想运行一个基于 Java 的服务器程序,我希望它完全接受交换。它的 -Xms 现在是 384,但这还不够。

Is there any solution?

有什么解决办法吗?

p.s.: swappiness is 60. I dont want to see this process in RAM :-)

ps:swappiness 是 60。我不想在 RAM 中看到这个过程 :-)

回答by Alper

cgroupsmay work for you. You can apply memory limit and once the process hits that limit, it will begin to swap.

cgroups可能对你有用。您可以应用内存限制,一旦进程达到该限制,它将开始交换。

There is a small example and explanation here.

有一个小例子,说明在这里

回答by BraveNewCurrency

No process can execute in swap "completely". The code+data must be loaded into RAM for the CPU to read/write/execute it. You can push things temporarily out to swap, but if your resident set is too small, you system will swap continuously. (Even with a SSD, loading from disk is thousands of time slower than loading from RAM.)

没有进程可以“完全”在交换中执行。代码+数据必须加载到 RAM 中,以便 CPU 读/写/执行它。你可以暂时把东西推出来交换,但如果你的常驻集太小,你的系统会不断地交换。(即使使用 SSD,从磁盘加载也比从 RAM 加载慢数千倍。)

This constant swapping will:

这种不断的交换将:

1) slow down your entire system, as some of the I/O bandwidth of your disk is constantly being used

1) 减慢整个系统的速度,因为磁盘的某些 I/O 带宽一直在使用

2) reduce the life of your SSD, as SSDs have a finite number of write cycles before they go bad.

2) 减少 SSD 的使用寿命,因为 SSD 在变坏之前的写入周期数是有限的。

Your best bet is just to create a large swap area, and run your program as normal. The OS will move the infrequently used bits out to disk. If you can't get good performance on the rest of the system, then you need more RAM. You can try to use ulimit and/or cgroups to limit the amount of RAM a process uses, but this cannot "fix" your problem.

最好的办法就是创建一个大的交换区,然后像往常一样运行你的程序。操作系统会将不常用的位移出到磁盘。如果您无法在系统的其余部分获得良好的性能,那么您需要更多的 RAM。您可以尝试使用 ulimit 和/或 cgroups 来限制进程使用的 RAM 量,但这不能“解决”您的问题。

Alternately, you could re-write the server in a more efficient language. (This is a common trade-off: The programmer could spend months optimizing the runtime CPU/memory footprint, or the business could spend more money on hardware.)

或者,您可以用更高效的语言重新编写服务器。(这是一个常见的权衡:程序员可能会花费数月时间来优化运行时 CPU/内存占用,或者企业可能会在硬件上花费更多的钱。)