clarification regarding SoftMaxHeapSize and AlwaysPreTouch

Stefan Johansson stefan.johansson at oracle.com
Wed Feb 14 09:24:29 UTC 2024


Hi Alen,

Some details below.

On 2024-02-14 09:45, Alen Vrečko wrote:
> Hello,
> 
> saw this write up https://malloc.se/blog/zgc-softmaxheapsize 
> <https://malloc.se/blog/zgc-softmaxheapsize>. I have a question 
> regarding AlwaysPreTouch. I could have missed it in the documentation 
> and write up. But I am wondering:
> 
> Doing -XX:SoftMaxHeapSize=2G -Xmx5G -XX:+AlwaysPreTouch
> 
> will this first commit 5G of native memory on start and then ZGC will 
> ZUncommit 3G? Alternative is to only pretouch up to 2G?
> 

It's actually not the maximum heap size that is the deciding factor 
here. At startup there are heuristics to decide an initial heap size 
(when not specified with -Xms or -XX:InitialHeapSize) and this is the 
amount of memory we will commit and pretouch at startup.

> With -XX:SoftMaxHeapSize=2G -Xmx5G -XX:+AlwaysPreTouch -XX:-ZUncommit 
> does this mean the heap will take 5G of native memory from the start and 
> stay that way?
> 

No, same as above, the initial heap size will be decided using 
heuristics or provided options. The only thing -ZUncommit change is that 
no memory that gets committed will later on be uncommitted and returned 
to the system.

Hope this clarifies things a bit,
StefanJ


> Thanks
> Alen


More information about the zgc-dev mailing list