Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the purpose of -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio

Kindly tell me the purpose of those options. After googling I think: MinHeapFreeRatio tells "specified minimum percentage of space will be ensured to be free in heap memory after a GC" and MaxHeapFreeRatio tells "no more than specified percentage of space will be free in heap memory after a GC" [if there is excess free memory than the specified percentage, those memory will be returned to OS]

When i tried these options with 10 as value for both, even where there is more than 80 percentage of free heap memory, it was not released back to OS.

Details:

Java HotSpot(TM) 64-Bit Server VM (1.5.0_15-b04, mixed mode) ParallelGC (otherwise known as throughput collector which is the default collector in server class VM) i specified -Xms50M and -Xmx1000M as jvm arguments OS: windows 7 professional (8 GB memory 64 bit OS)

Note: i just tried with SerialGC too, those min and max heap free ratio options were ignored.

like image 820
Praveen Kumar Avatar asked Apr 17 '13 11:04

Praveen Kumar


1 Answers

The best explanation of the parameters -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio parameters are available in the oracle garbage documentation:

https://docs.oracle.com/javase/10/gctuning/factors-affecting-garbage-collection-performance.htm

-XX:MinHeapFreeRatio=40
-XX:MaxHeapFreeRatio=70

With these options, if the percent of free space in a generation falls below 40%, then the generation expands to maintain 40% free space, up to the maximum allowed size of the generation. Similarly, if the free space exceeds 70%, then the generation contracts so that only 70% of the space is free, subject to the minimum size of the generation.

I combine it with the G1GC in this way:

-XX:+UseG1GC -XX:MinHeapFreeRatio=2 -XX:MaxHeapFreeRatio=10

With this result:

Heap size over time with the explained parammeters

like image 160
Martin Avatar answered Sep 19 '22 09:09

Martin