What does 'MaxRAM' JVM parameter signify? - java

I'm looking at the configuration of a JVM running on a linux server. when I run
java -XX:+PrintFlagsFinal | less | grep -iE 'MaxRam'
Which seems to basically print out just about every parameter the JDK knows about
I see
uint64_t MaxRAM = 137438953472 {pd product}
but I can't seem to find much documentation on this flag.
I found that "{pd product}" signifies "Platform Dependent Product: An officially supported, internal JVM option"
Anyone know exactly what this parameter signifies, or where I can read in more detail about platform specific JVM flags?
Misc details:
Java -version:
.
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
uname -a
Linux [SERVERNAME] 2.6.32-431.17.1.el6.x86_64 #1 [DATE] x86_64 x86_64 x86_64 GNU/Linux

According to Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide document the value in MaxRAM is used to calculate the Default Heap Size if no initial heapsize and max heap size is specified and contains as posted previously
Default Heap Size
Unless the initial and maximum heap sizes are specified on the command line, they are calculated based on the amount of memory on the machine. The proportion of memory to use for the heap is controlled by the command-line options InitialRAMFraction and MaxRAMFraction
[...]
The value of MaxRAM is platform-dependent.
Referring to the The Java Virtual
Machine Specification the size of the heap can change, depending of the implementation of the JVM.
The heap may be of a fixed size or may be expanded as
required by the computation and may be contracted if a larger heap becomes
unnecessary. The memory for the heap does not need to be contiguous.
A Java Virtual Machine implementation may provide the programmer or the user control
over the initial size of the heap, as well as, if the heap can be dynamically expanded or
contracted, control over the maximum and minimum heap size.
And to answer your platform specific JVM flags question:
Java HotSpot VM Options

Related

What does UseContainerSupport VM parameter do?

What does this option do in docker file?
ENTRYPOINT java -XX:+UseContainerSupport $JAVA_OPTIONS -jar /myapp.jar
Will the docker container start without this parameter?
I checked one article which says
enable memory support
but it is still not clear to me.
Starting from Java 10, this parameter (which is enabled by default) is used to make the JVM take the container memory limits into account when allocating the heap size, not the host machine configuration.
This option was backported to Java 8:
https://www.oracle.com/technetwork/java/javase/8u191-relnotes-5032181.html
Examples:
If you run:
docker run **-m 1gb** openjdk:8u131 java -XshowSettings:vm -version
The result is going to be (on my machine Ubuntu with 8gb)
Max. Heap Size (Estimated): 1.68G
I set a memory limit for the container but it ignored and used the host config (it uses by default total memory/4)
Now if I run the version that has the new feature (link above) you can see that the container memory limite was taken into account:
docker run **-m 1g** openjdk:8u191-jre-alpine java -XshowSettings:vm -version
Result (total memory / 4):
VM settings:
Max. Heap Size (Estimated): 247.50M
Ergonomics Machine Class: server
Using VM: OpenJDK 64-Bit Server VM
openjdk version "1.8.0_191"
At the time I'm writing this the LATEST version of the openjdk:8 image is 222 so you can use this version. That has the feature included.
For more information:
Explains this flag use in Java 10: https://medium.com/adorsys/jvm-memory-settings-in-a-container-environment-64b0840e1d9e
Using this flag with Java 8: https://blog.softwaremill.com/docker-support-in-new-java-8-finally-fd595df0ca54
Yes. The container will start without -XX:+UseContainerSupport.
-XX:+UseContainerSupport is used to allocate a larger fraction of memory.
To prevent the JVM adjusting the maximum heap size when running in a container, set -XX:-UseContainerSupport.
In addition to that, https://www.eclipse.org/openj9/docs/xxusecontainersupport/ might be helpful.

What is the default max heap size (-Xmx) in Java 8?

In the oracle documentation I found:
-Xmxsize Specifies the maximum size (in bytes) of the memory allocation pool in bytes ... The default
value is chosen at runtime based on system configuration.
What does system configuration mean?
It varies on implementation and version, but usually it depends on the VM used (e.g. client or server, see -client and -server parameters) and on your system memory.
Often for client the default value is 1/4th of your physical memory or 1GB (whichever is smaller).
Also Java configuration options (command line parameters) can be "outsourced" to environment variables including the -Xmx, which can change the default (meaning specify a new default). Specifically the JAVA_TOOL_OPTIONS environment variable is checked by all Java tools and used if exists (more details here and here).
You can run the following command to see default values:
java -XX:+PrintFlagsFinal -version
It gives you a loooong list, -Xmx is in MaxHeapSize, -Xms is in InitialHeapSize. Filter your output (e.g. |grep on linux) or save it in a file so you can search in it.
Like you have mentioned, The default -Xmxsize (Maximum HeapSize) depends on your system configuration.
Java8 client takes Larger of 1/64th of your physical memory for your Xmssize (Minimum HeapSize) and Smaller of 1/4th of your physical memory for your -Xmxsize (Maximum HeapSize).
Which means if you have a physical memory of 8GB RAM, you will have Xmssize as Larger of 8*(1/64) and Smaller of -Xmxsizeas 8*(1/4).
You can Check your default HeapSize with
In Windows:
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"
In Linux:
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
These default values can also be overrided to your desired amount.
Surprisingly this question doesn't have a definitive documented answer. Perhaps another data point would provide value to others looking for an answer. On my systems running CentOS (6.8,7.3) and Java 8 (build 1.8.0_60-b27, 64-Bit Server):
default memory is 1/4 of physical memory, not limited by 1GB.
Also, -XX:+PrintFlagsFinal prints to STDERR so command to determine current default memory presented by others above should be tweaked to the following:
java -XX:+PrintFlagsFinal 2>&1 | grep MaxHeapSize
The following is returned on system with 64GB of physical RAM:
uintx MaxHeapSize := 16873684992 {product}
On my Ubuntu VM, with 1048 MB total RAM, java -XX:+PrintFlagsFinal -version | grep HeapSize printed : uintx MaxHeapSize := 266338304, which is approx 266MB and is 1/4th of my total RAM.
As of 8, May, 2019:
JVM heap size depends on system configuration, meaning:
a) client jvm vs server jvm
b) 32bit vs 64bit.
Links:
1) updation from J2SE5.0: https://docs.oracle.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html
2) brief answer: https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html
3) detailed answer: https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#default_heap_size
4) client vs server: https://www.javacodegeeks.com/2011/07/jvm-options-client-vs-server.html
Summary:
(Its tough to understand from the above links. So summarizing them here)
1) Default maximum heap size for Client jvm is 256mb (there is an exception, read from links above).
2) Default maximum heap size for Server jvm of 32bit is 1gb and of 64 bit is 32gb (again there are exceptions here too. Kindly read that from the links).
So default maximum jvm heap size is: 256mb or 1gb or 32gb depending on VM, above.

Why is my JBoss wrapper application JVM restarted?

My OS version is Windows 7 64 bit and the JDK is 32 bit version. I started my JBoss Wrapper Application successfully, but after it ran for a while the JVM failed and restarted.
The message in the JVM dump log is:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 543672 bytes for Chunk::new
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (allocation.cpp:328), pid=5480, tid=4740
#
# JRE version: 7.0_05-b05
# Java VM: Java HotSpot(TM) Server VM (23.1-b03 mixed mode windows-x86 )
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
I deploy 3 wrapper applications on my computer. Each of them set to a maximum JVM heap size of 700Mb.
Please help me review this problem. thanks. My questions are:
How can I know current JVM allocated size?
What is the reason for this problem?
How can fix it? Someone recommended me to use the 64 bit JDK. Is it necessary?
If you use 32-bit JDK, the maximum heap size we can set and still have the JVM start up is about 1.2 GB.For larger heaps, we need to run a 64-bit JDK. To run 64-bit JDK, you’d also need a64-bitoperating system running on a server that has a64-bit` CPU.
Downloaded the JDK 64 bit version
Set the JAVA_OPTS to
JAVA_OPTS=-Xms1024m -Xmx1024m -XX:MaxPermSize=256m
and refer this link.
Also this is good article about memory.
32-bit JVM are limited to a 2GB heap maximum (-Xmx). In some operating systems, much less than that.
A 64-bit JVM will not have this limitation.
In Windows, you can follow your JVM's memory consumption with
Task Manager->Processes.

increase maximum representable size for java heap space over 6GB on MAC

I'm working with an Model Checker on a Mac 10.6.8 64-Bit machine (32 GB Ram). My problem is that I can't reserve more than ~ 2 GB heap space.
I tried for example this :
./mymodelchecker -vmargs -d64 -Xms6g -Xmx6g
But I get this error-message :
Invalid initial heap size: -Xms6g The specified size exceeds the maximum representable size.
It seems to me that he heap space is working in a 32-Bit environment, but the machine is 64-Bit, Java is through -d64 is in 64-Bit mode and my Model Checker supports 64-Bit architecture.
How can I increase the maximum representable size of my heap space?
You need to modify the mymodelchecker script, find the line that actually instantiates the java program and add -Xms6g -Xmx6g arguments.
Also, perhaps the model checker has a configuration/property file where you can set VM arguments without modifying the startup script.
You can also checkout the top -p #processId to check if the stated heap is allocated to the process or not. look at the virtual memory allocated in the top report:
ps -aef | grep <your process identifier>
top -p <the process id of the process as returned by the previous statement>

Tomcat problem - Could not reserve enough space

I am running server with 256MB RAM. Maximum heap size I can allocate for Java is 110MB. When I add those param to JAVA_OPTS I can run java -version. Problem is that I can not run Tomcat with these parameters. Maximum heap size for Tomcat to run is 40MB. I do not know why I can not allocate more memory?
Of course I get error:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Set CATALINA_OPTS to -Xmx110m, JAVA_OPTS. I suppose you could set both, to be sure.
The Xmx flag may be ignored when you run the java executable with the -version flag. This depends on how you pass the version flag. The following are the results on my machine with 2GB RAM:
Version flag passed before Xmx
C:\Users\Reynolds>java -version -Xmx10240M
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
which is weird considering that 10G is beyond the max addressable limit on memory in a 32-bit environment.
Version flag passed after Xmx
C:\Users\Reynolds>java -Xmx10240M -version
Invalid maximum heap size: -Xmx10240M
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
C:\Users\Reynolds>java -Xmx1524M -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
which is closer to reality.
You might want to verify how much contiguous memory is available to Java in reality, using the second approach, and then decide on an optimal value for the maximum heap size.
The error message suggests you do not have enough free RAM try closing other applications and seeing if you can allocate a larger heap then. You may need more RAM I am afraid.

Categories

Resources