<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">I’m trying to test the container support that I’m adding to </span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">JDK 18.3 and I’m running into an issue with the Heap size calculation.</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">If I create a docker container that has 100MB of total memory on a</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">64-bit Linux box, I’m ending up with a 126MB Max Heap which results</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class="">in the process getting killed by the OOM killer.</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">This is due to the fact that MaxHeapSize is 126MB and phys_mem (100MB) is</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">not less than 50% of MinRAMPercentage of MaxHeapSize.</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">I would think in a small memory system, you don’t ever want the Heap </span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">size to be more </span><span style="color: rgb(0, 0, 0);" class="">than somewhere around 70% of total RAM. </span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class="">A quick fix for my problem might be this, but this still</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class="">leaves some pathological cases where phys_mem is greater than but</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class="">close to MaxHeapSize.</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><div style="margin: 0px; line-height: normal; color: rgb(82, 48, 225);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">if phys_mem < MaxHeapSize || phys_mem < MaxHeapSize * MinRAMPercentage</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> use phys_mem * MinRAMPercentage</span></div><div class=""><br class=""></div><div class="">I could improve on this with:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; color: rgb(82, 48, 225);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">if MaxHeapSize > 70% of phys_mem || phys_mem < MaxHeapSize * MinRAMPercentage</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> use phys_mem * MinRAMPercentage</span></div></div></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">Here’s the code from arguments.cpp</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// If the maximum heap size has not been set with -Xmx,</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// then set it as fraction of the size of physical memory,</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// respecting the maximum and minimum sizes of the heap.</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #afad24" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (FLAG_IS_DEFAULT(MaxHeapSize)) {</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / </span><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">100</span><span style="font-variant-ligatures: no-common-ligatures" class="">);</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #afad24" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (phys_mem <= (julong)((MaxHeapSize * MinRAMPercentage) / </span><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">100</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) {</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Small physical memory, so use a minimum fraction of it for the heap</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> reasonable_max = (julong)((phys_mem * MinRAMPercentage) / </span><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">100</span><span style="font-variant-ligatures: no-common-ligatures" class="">);</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> } </span><span style="font-variant-ligatures: no-common-ligatures; color: #afad24" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Not-small physical memory, so require a heap at least</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; color: rgb(82, 48, 225); background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// as large as MaxHeapSize</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Let me know what you think. </span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Bob.</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Courier New'; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></body></html>