Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

java - Setting -XX:MaxRam

According to this link, there is an option to set MaxRamSize manually to restrict the JVM to not use memory beyond this. But I have not seen any documentation of the same. I've never known this. Is there anything like this or anything similar? PS. I know and I'm not looking to set heap/stack/metaspace/native memory sizes. I just would like to know if there is an overall memory limiting option.

Trying it did not help as It errored out:

Improperly specified VM option 'MaxRAM=1073741824B'
Could not create the Java Virtual Machine.
A fatal exception has occurred. Program will exit.

Infact according to this link open-jdk seems to have these options. Another link that I found I believe points to set the heap size. Which again is not looking for. But this is for Oracle I guess.

Why I'm looking for this kind of an option to run the application inside a container (Like Docker) and prevent the application from being killed by the OOM Killer. What I believe is if there is a setting of such the java application would error or crash with a java.lang.OutOfMemoryError rather, than the container being terminated.

My assumptions and understandings may be totally wrong. This question may also be totally wrong and irrelevant. But of course, asking is the way forward :).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why I'm looking for this kind of an option to run the application inside a container (Like Docker) and prevent the application from being killed by the OOM Killer.

This is exactly the option you are looking for. Moreover, it was properly integrated with cgroups (~docker) as part of JDK-8170888. Note that this flag does not prevent JVM from allocating more memory than its value, but rather gives a hint "I know my physical RAM limit is X, please allocate within X", so JVM will share this value between Java heap and native memory. But if e.g. your application has native memory leak or classloader leak, then this limit will be reached anyway.

JVM is complaining on MaxRAM=1073741824B because it doesn't expect B in the end, it should be declared as -XX:MaxRAM=1073741824. See the description of the flag: Real memory size (in bytes) used to set maximum heap size.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...