Java JVM 如何使用超过 4GB 的内存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3143579/
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
how can JVM use more than 4gb of memory
提问by reg
I have a request to install a Linux server (preferably Ubuntu 64bit server), and Java (64 bit) on the following machine:
我请求在以下机器上安装 Linux 服务器(最好是 Ubuntu 64 位服务器)和 Java(64 位):
- Intel Core2Quad Q8200 - 2.33 GHz
- 8gb DDR2 ram
- 2x 320GB SATA HDD in soft RAID1 mirror (mirror)
- 英特尔酷睿 2Quad Q8200 - 2.33 GHz
- 8GB DDR2 内存
- 2x 320GB SATA HDD in soft RAID1 mirror (mirror)
The problem is how to configure system and Java because I need JVM to use more than 4gb of memory.
问题是如何配置系统和Java,因为我需要JVM使用超过4GB的内存。
It cannot be distributed on many virtual machines. There is data more than 4GB large and it has to be in memory because HDD is slow and performance is critical.
它不能分布在许多虚拟机上。有超过 4GB 的数据,它必须在内存中,因为 HDD 速度慢且性能至关重要。
This is a configuration and performance question and I am interested in comments if anyone has experience?
这是一个配置和性能问题,如果有人有经验,我对评论感兴趣?
thank you very much for helping me on this...
非常感谢你在这方面帮助我...
回答by skaffman
A 64 bit JVM should have no problem at all with giant heaps, certainly much larger than your available RAM. Just increase the heap size when you start the JVM, for example:
一个 64 位 JVM 应该完全没有问题,因为巨大的堆肯定比可用的 RAM 大得多。只需在启动 JVM 时增加堆大小,例如:
java -Xmx6g
You used to have to specify the 64bit flag (with -d64
), but I don't think this is necessary any more.
您过去必须指定 64 位标志(使用-d64
),但我认为不再需要这样做了。
32bit JVMs can manage something like 3GB of heap.
32 位 JVM 可以管理类似 3GB 的堆。
回答by Thorbj?rn Ravn Andersen
If you install a 64-bit Ubuntu, I believe that
如果你安装 64 位 Ubuntu,我相信
sudo apt-get install sun-java6-jdk
gives you a 64-bit Java.
为您提供 64 位 Java。
EDIT: The 64 bit Java can give you as much memory as you need with the appropriate switches. The limit is with the 32-bit JVM's which cannot go over 2-4 Gb depending on operating system.
编辑:64 位 Java 可以通过适当的开关为您提供所需的内存。限制是 32 位 JVM,它不能超过 2-4 Gb,具体取决于操作系统。
回答by Andreas
skaffman's answer which provides the required flag for allocating 6GB of memory is correct. If the 'g' does not do the trick you might want to try 6000m (check the link below for details on flags/platform)
提供分配 6GB 内存所需标志的 skaffman 的答案是正确的。如果 'g' 不起作用,您可能想尝试 6000m(有关标志/平台的详细信息,请查看下面的链接)
For other options you can find useful information on all available options for the Java HotSpot VM here.
对于其他选项,您可以在此处找到有关 Java HotSpot VM 的所有可用选项的有用信息。
http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp
http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp
(Behavioral and performance options are available. Platform specific links also available on this page)
(提供行为和性能选项。此页面上还提供了特定于平台的链接)
回答by Denis Tulskiy
JVM (especially 64bit) does not hesitate taking all the memory, and 4Gb is not a problem. Just install 64-bit Ubuntu and default-jre package will also be 64 bit.
JVM(尤其是64bit)毫不犹豫地把所有的内存都拿走,4Gb不是问题。只需安装 64 位 Ubuntu,default-jre 包也将是 64 位。
Also take special care about how your data is stored in memory. Again, 64-bit JDK is very hungry for memory due to higher overhead for pointers etc. so if you distribute these 4Gb in small chunks in some data structure, 8Gb will not be enough.
还要特别注意数据在内存中的存储方式。同样,由于指针等的开销较高,64 位 JDK 非常需要内存,因此如果您将这些 4Gb 分配在某些数据结构中的小块中,8Gb 将是不够的。