Why is the max heap much smaller than the value I set in Xmx (with -XX:+UseParallelGC -XX:+UseParallelOldGC)

I am running a SolrCloud on k8s with the following setting:

Heap params:

-server -Xms280m -Xmx312m

Other params:

-XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy -XX:ParallelGCThreads=4 -XX:AdaptiveSizePolicyOutputInterval=1 -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:MaxGCPauseMillis=300 -XX:GCTimeRatio=19 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=128m -XX:MaxMetaspaceFreeRatio=90 -XX:MetaspaceSize=96m -XX:+ParallelRefProcEnabled

And the max heap shown on the admin page is only 277.5m, which is 34.5m less than Xmx

enter image description here

And if I change the heap params to

-server -Xms312m -Xmx312m

Then the max heap is around 300m, which is much closer to the Xmx

My questions is that:

  • Why is there such a big difference in the first setting?
  • Why does the difference get smaller when I set Xms = Xmx
  • Would JVM still honor my Xmx setting? (Would my application still be allowed to grow to 312m?)

More observations…

I’ve tried this with another memory setting:

-server -Xms296m -Xmx360m

and the max heap shown on Solr’s admin UI is 320m

After doing some math, it seems that the max heap is always around 90% of the Xmx I set.

  312 * 0.9 = 280.8 (just 3.3m more than 277.5m)
  360 * 0.9 = 324  (just 4m more than 320m)

Why is this happening?

Answer

So here is some details.

-Xmx = maximum java heap

-Xms = initial and minimum java heap

The -Xmx option and -Xms option in combination are used to limit the Java heap size. The Java heap can never grow larger than -Xmx. Also, the -Xms value can be used as “minimum heap size” to set a fixed heap size by setting -Xms = -Xmx.

However -Xmx does not limit the total amount of memory that the JVM can use.

Here is my answer inline

Why is there such a big difference in the first setting?

It’s because of difference between initial memory and max memory heap.

Why does the difference get smaller when I set Xms = Xmx

For production system I would suggest use same, reason is you will get kick start and less gc most of the time, again it’s depend on workload and system profiling and nature of application.

Would JVM still honor my Xmx setting? (Would my application still be
allowed to grow to 312m?)

Answer is yes, but don’t confuse with Xmx and JVM. Heap will grow when application need more resources.

EDIT 1:

Heap having these 3 parts:

  1. Eden
  2. Survivor
  3. Tenured
  4. Reserved

Per your snapshot it shows 3 parts till 195.13MB till 209.50MB till 277.50MB and rest if reserved.

Hope this will help.

Attribution
Source : Link , Question Author : John the Traveler , Answer Author : asktyagi

Leave a Comment