A Java container is OOM-killed at 512 MB. Why isn't the heap the whole story?
IntermediateScenarioLimits, logging, health checks and restarts
Answer
Situation read → JVM memory includes heap, metaspace, thread stacks, code cache and native buffers.
What I'd do →
- Use container-aware flags:
-XX:MaxRAMPercentage=70. - Check
docker inspect -f '{{.State.OOMKilled}}' canddmesg | grep -i oom. - Add native memory tracking
-XX:NativeMemoryTracking=summaryand size the limit accordingly.
Why → The cgroup counts total RSS, not just heap.
Interview tip → Leave 25–30% headroom above heap.
More on Limits, logging, health checks and restarts
How do you cap CPU and memory for a container and what happens on exceed?BeginnerLatency spikes though CPU usage looks low (50%).Advanced`docker logs` is empty but the app is running.BeginnerConfigure log rotation globally.BeginnerShip container logs to a central system.IntermediateDefine a good restart policy for a production service.Beginner