Releasing unused memory

Per Liden per.liden at oracle.com
Thu Oct 18 07:59:22 UTC 2018


Hi all,

I was asked if ZGC returns heap memory to the OS when it's no longer 
needed. I thought I should share that answer here, in case others have 
had the same question. The answer is no, ZGC currently doesn't do that. 
However, doing that is fairly straight forward and a quick-and-dirty 
patches for doing that exists. So if you looking for this feature and 
want to try it out I uploaded the patch here:

http://cr.openjdk.java.net/~pliden/zgc/zrelease_unused_heap/webrev.0/

Enable it using the -XX:+ZReleaseUnusedHeap option. However, note that 
it does come with a performance hit (in favor of memory usage). Also 
note that it doesn't work in combination with -XX:+UseLargePages.

A more refined version of the patch will most likely be upstreamed at 
some point in the future, but there are some things to consider before 
we do that. For example, when this is enabled, we probably also want 
this to affect ZGC's heap grow heuristics so that we not only return 
memory we don't need but also so that we're more conservative about 
growing the heap in the first place. Also, the current patch returns 
memory very aggressively. To reduce the impact on performance, we might 
want to only release memory that have gone unused for some amount of time.

cheers,
Per


More information about the zgc-dev mailing list