一个简单的“Hello World"在 64 位机器上需要 10G 虚拟内存,而在 32 位机器上需要 1G? [英] A simple "Hello World" needs 10G virtual memory on a 64-bit machine vs 1G at 32-bit?
问题描述
在我们的生产机器上运行一个简单的 Java 程序,我注意到这个程序消耗了更多 10G 的 virt.我知道虚拟内存不是那么重要,但至少我想了解为什么需要它.
Running a simple Java program on our production machine, I noticed that this program eats up more 10G virt. I know that virtual memory is not that relevant, but at least I would like to understand why this is needed.
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
try {
Thread.sleep(10000);
} catch(InterruptedException e) {
/* ignored */
}
}
}
当我运行那个小程序时,top
在说:
Heres what top
is saying when i run that little program:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18764 myuser 20 0 10.2g 20m 8128 S 1.7 0.1 0:00.05 java
有人知道为什么会这样吗?
Does anyone know why this is happening?
uname -a 说:
uname -a says:
Linux m4fxhpsrm1dg 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
在较旧的 32 位 linux 机器上,相同的程序仅消耗大约 1G virt.旧机4GB内存,新机32GB.
On an older 32bit-linux machine the same program consumes only about 1G virt. The old machine has 4GB RAM, the new one 32GB.
推荐答案
初始堆和最大堆的默认大小 被定义为机器物理内存的百分比,如今生产服务器往往拥有一大堆.
The default sizes for initial heap and maximum heap are defined as a percentage of the machine's physical memory, of which a production server nowadays tends to have a whole lot.
您可以通过-Xms 和-Xmx 命令行选项来选择两者.
这篇关于一个简单的“Hello World"在 64 位机器上需要 10G 虚拟内存,而在 32 位机器上需要 1G?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!