Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why max heap is changing at runtime?

We have a Java application running in openjdk8 whose max heap memory changes at runtime - what might be the reason of that?

I have found question Why the heap is changing in java which points to the article which explains difference between max and committed memory. It seems that in our case these two are usually the same, but not always - see at 11:53 on screenshots below.

Heap can be also changed be young generation serial collector (-XX:MaxHeapFreeRatio, see Encourage the JVM to GC rather than grow the heap?), however we use parallel collector so this is not the case.

The memory related JVM parameters that we run the application with:

-XX:MaxMetaspaceSize=200M -Xms2000m -Xmx2000m

Not sure if it's related, the application was doing parallel mark sweep on old generations between 11:55 and 11:58 - at this time there was over 200MB free memory available and we cannot see any reason for that behaviour.

Heap Memory Mark Sweep Count

like image 250
Jaroslaw Pawlak Avatar asked Mar 21 '18 12:03

Jaroslaw Pawlak


People also ask

Why does heap memory increase?

The heap is increasing continuously, because there are allocations, up until the garbage collector runs and reclaims the memory. That's the normal pattern of garbage collected heaps.

Can heap size change?

The heap memories for either server are created at the JVM start-up with a default value of 4096 MB. If the default value is insufficient to suit the memory consumption of either server, you can change the maximum heap size to a value that ranges between 4096 and 8192 Mbytes.

What is default JVM max heap size?

The Java™ virtual machine (JVM) heap size setting directly relates to how many server instances can be started within a dynamic cluster on a specific node. You might need to modify the JVM heap size setting based on your environment configuration. The default value is 256 MB.


1 Answers

You are using Parallel GC which has adaptive size policy on by default.
Set -XX:-UseAdaptiveSizePolicy if you don't want heap generations to resize.

like image 78
apangin Avatar answered Sep 28 '22 02:09

apangin