Why isn't the allocated heap memory shrinking when usage is below MaxHeapFreeRatio?

筅森魡賤 提交于 2019-12-05 17:17:57

There are apparently various factors that can cause MaxHeapFreeRatio to not be honoured:

The amount of memory reserved from the operating system for the heap is determined by min heap and max heap, the parameters -Xms and -Xmx on the java command line. The various garbage collector ratios and other configurations are all internal to that and don't affect how much total memory JVM uses, just how it arranges things in that memory.

Commonly when people set up servers they set it so that -Xms and -Xmx are the same value, to avoid additional performance cost of resizing the heap and having to create contiguous memory space while the server is running if the heap needs to grow. This means that the amount of memory reserved from the operating system for heap will never shrink as a result of garbage collection, it just gets freed up to have new JVM data put in.

In JRE 1.7 you can use -XX:+UseG1GC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=15 . However, to get memory shrinked you still need to invoke GC explicitly by calling System.gc().

I used combination -XX:+UseG1GC -XX:ParallelGCThreads=15 -XX:MinHeapFreeRatio=30 -XX:MaxHeapFreeRatio=70 -verbosegc -XX:+PrintGCDetails -Dsun.rmi.dgc.client.gcInterval=60000 -Dsun.rmi.dgc.server.gcInterval=100000 and it saved my system crashing used memory goes to 99.8% and then release.

Thanks: Shahid abbasi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!