简体   繁体   English

如何保证将特定GB分配为JVM的堆内存

[英]How to guarantee allotment of particular GB as off heap memory for a JVM

-Xmx10g guarantees that the JVM gets 10G from OS for the process. -Xmx10g保证JVM从OS获取10G进程。 Similarly, I want to guarantee particular amount of memory (say 4g) for my off heap usage. 同样,我想为我的off heap使用保证特定的内存量(比如说4g)。

If the RAM of my machine is 8GB and Xmx for my java process is 2G. 如果我的机器的RAM是8GB,我的java进程的Xmx是2G。 Now, there may be other processes that may eat some memory. 现在,可能还有其他进程可能会占用一些内存。 So, when I want to start my JVM, i want to specify the amount of off heap memory that i want to use inside my JVM. 所以,当我想启动我的JVM时,我想指定我想在JVM中使用的关闭堆内存量。

-XX:MaxDirectMemorySize specifies only max direct memory size. -XX:MaxDirectMemorySize仅指定最大直接内存大小。

How can I ensure guaranteed availability of particular size of off-heap memory? 如何确保特定大小的堆外内存的保证可用性? Is there any parameter for that. 有没有任何参数。

Your understanding of the parameter -Xmx10g isn't quite correct. 您对参数-Xmx10g理解不太正确。 It allows the JVM to ask the operating system for up to 10GB of memory for its heap. 它允许JVM向操作系统询问其堆的最多10GB内存。 It doesn't guarantee that the JVM will get it. 它不能保证JVM能够获得它。 Indeed, if your system doesn't have sufficient memory (physical and paging), the JVM won't get it. 实际上,如果您的系统没有足够的内存(物理和分页),JVM将无法获得它。

For other memory (other than the heap), the JVM will ask for it and get it if there is sufficient. 对于其他内存(除了堆),JVM会询问它并在有足够的时候获取它。 But again, there are no guarantees and there is no parameter for guarantees. 但同样,没有保证,也没有保证参数。

I suggest using memory mapped files for off heap as these are more flexible in handling over committed sizes. 我建议将内存映射文件用于off heap,因为这些文件在处理提交的大小时更灵活。

In your case, you may need a startup program or script to choose the heap size, unless you can make the heap size 2 GB always given you have decided this is enough. 在您的情况下,您可能需要一个启动程序或脚本来选择堆大小,除非您可以确定堆大小为2 GB,因为您已经确定这已经足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM