<div dir="ltr">Hello everyone.<div><br></div><div>I did my best to search the web for any prior discussion on this. Haven't found anything useful.</div><div><br></div><div>I am trying to understand why there is a noticeable difference between the size of all objects on the heap and the heap used (after full GC). The heap used size can be 10%+ more than the size of of all live objects.</div><div><br></div><div>Let's say I want to fill 1 GiB heap with 4MiB byte[] objects.</div><div><br></div><div>Naively I'd imagine I can store 1 GiB / 4MiB = 256 such byte[] on the heap.</div><div><br></div><div>(I made a simple program that just allocates byte[], stores it in a list, does GC and waits (so I can do jcmd or similar), nothing else)</div><div><br></div><div>With EpsilonGC -> 255x 4MiB byte[] allocations, after this the app crashes with out of memory</div><div>With SerialGC  -> 246x</div><div>With ParallelGC -> 233x<br></div><div>With G1GC -> 204x</div><div>With ZGC -> 170x<br></div><div><br></div><div>For example in the ZGC case, where I have 170x of 4MiB byte[] on the heap.</div><div><br></div><div>GC.heap_info:</div><div><br></div> ZHeap           used 1022M, capacity 1024M, max capacity 1024M<br> Metaspace       used 407K, committed 576K, reserved 1114112K<br>  class space    used 24K, committed 128K, reserved 1048576K<div><br></div><div>GC.class_histogram:</div><div><br></div>Total         15118      713971800 (~714M)<div><br></div><div>In this case does it mean ZGC is wasting 1022M - 714M = 308M for doing its "thing"? This is like 1022/714= 43% overhead?</div><div><div><br></div><div>This example might be convoluted and atypical of any production environment.</div><div><br></div><div>I am seeing the difference between live set and heap used in production at around 12.5% for 3 servers looked at.</div><div><br></div><div>Is there any other way to estimate the overhead apart from looking at the difference between the live set and heap used? Does ZGC have any internal statistic of the overhead?</div><div><br></div><div>I'd prefer not to assume 12.5% is the number to use and then get surprised that in some case it might be 25%?</div><div><br></div><div>Do you have any recommendations regarding ZGC overhead when estimating heap space?</div><div><br></div><div>Thank you</div><div>Alen</div></div></div>