Heap Size Ergonomics in docker containers

Bob Vandette bob.vandette at oracle.com
Tue Oct 24 18:43:47 UTC 2017


I’m trying to test the container support that I’m adding to 
JDK 18.3 and I’m running into an issue with the Heap size calculation.

If I create a docker container that has 100MB of total memory on a
64-bit Linux box, I’m ending up with a 126MB Max Heap which results
in the process getting killed by the OOM killer.

This is due to the fact that MaxHeapSize is 126MB and phys_mem (100MB) is
not less than 50% of MinRAMPercentage of MaxHeapSize.

I would think in a small memory system, you don’t ever want the Heap 
size to be more than somewhere around 70% of total RAM.  

A quick fix for my problem might be this, but this still
leaves some pathological cases where phys_mem is greater than but
close to MaxHeapSize.

if phys_mem < MaxHeapSize || phys_mem < MaxHeapSize * MinRAMPercentage
   use phys_mem * MinRAMPercentage

I could improve on this with:

if MaxHeapSize > 70% of phys_mem || phys_mem < MaxHeapSize * MinRAMPercentage
   use phys_mem * MinRAMPercentage

Here’s the code from arguments.cpp

  // If the maximum heap size has not been set with -Xmx,
  // then set it as fraction of the size of physical memory,
  // respecting the maximum and minimum sizes of the heap.
  if (FLAG_IS_DEFAULT(MaxHeapSize)) {
    julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
    if (phys_mem <= (julong)((MaxHeapSize * MinRAMPercentage) / 100)) {
      // Small physical memory, so use a minimum fraction of it for the heap
      reasonable_max = (julong)((phys_mem * MinRAMPercentage) / 100);
    } else {
      // Not-small physical memory, so require a heap at least
      // as large as MaxHeapSize
      reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
    }

Let me know what you think.  
Bob.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/hotspot-gc-dev/attachments/20171024/26bd21e5/attachment.htm>


More information about the hotspot-gc-dev mailing list