[RFC 8285277] - How should the JVM handle container memory limits

David Holmes david.holmes at oracle.com
Thu Apr 21 02:30:44 UTC 2022


On 21/04/2022 4:09 am, Ioi Lam wrote:
> I would like to have a discussion on how (or whether) the JVM should 
> handle container memory limits -- see JDK-8285277 [1]
> 
> 
> The JVM may be terminated by the Linux OOM killer if it tries to use 
> more memory than the memory limit specified for a container. JDK-8284900 
> [2] tries to avoid OOM by checking InitialHeapSize against the memory 
> limit. However, this is incomplete because the JVM can use memory in 
> other ways:
> 
> - If -Xmx is larger than -Xms, the heap may expand
> - malloc memory
> - code cache
> - thread stacks
> 
> We have several choices:
> 
> (a) Following the direction of JDK-8284900, check for the initial memory 
> usage  of other types of memory as well. The problem with this is that 
> checking the "initial" usage some type of memory usage (malloc or stack) 
> is difficult or impossible.
> 
> (b) Avoid committing more memory when the total memory usage is close to 
> the limit. E.g., avoid expanding the Java heap, or return NULL from 
> os::malloc(). The problem is that some operations in the VM cannot 
> handle malloc failure and will terminate the VM anyway. Also, trying to 
> obey the memory limit with concurrent allocator/deallocator threads is 
> probably difficult or impossible.
> 
> (c) Do not consider the memory limit and let the VM be killed by the OOM 
> killer. This may be what the user wants -- the user knows that the app 
> will normally run within the memory limit, so if the heap expands too 
> much the app probably has a memory leak and should be killed, to be 
> automatically restarted by an external mechanism (such as Kubernetes).

I guess a combo of (a) and (c). Any memory limit imposed by a container 
should appear as the value of "available memory" just as if not in a 
container. So we have been taking available memory into account since 
day one and making some ergonomic decisions based on that, but not going 
out of our way to try and avoid the OOMKiller. So I don't see why 
container memory limits change anything - as long as we apply those 
limits correctly.

Cheers,
David

> 
> [1] https://bugs.openjdk.java.net/browse/JDK-8285277
> [2] https://bugs.openjdk.java.net/browse/JDK-8284900
> 


More information about the hotspot-dev mailing list