I have container with ~112 GB memory in Kubernetes. Single java application (Spring Boot) is deployed in it. Print args shows this
...Application - -server -Dspring.profiles.active=prod -Xms110g -Xmx110g
Output from JVM shows than only 36GB heap available for process.
private static final long GIGABYTE = 1024L * 1024L * 1024L;
public static float bytesToGigabytes(long bytes) {
return Math.floorDiv(bytes / GIGABYTE, 3);
}
public void getMemUsed() {
// Get the Java runtime
Runtime runtime = Runtime.getRuntime();
// Run the garbage collector
runtime.gc();
// Calculate the used memory
long memory = runtime.totalMemory() - runtime.freeMemory();
log.info("RAM Used %.3fGb of %.3fGb (max %.3fGb)".formatted(
bytesToGigabytes(memory), bytesToGigabytes(runtime.totalMemory()), bytesToGigabytes(runtime.maxMemory())));
}
prints
RAM Used 0.000Gb of 36.000Gb
...
RAM Used 29.000Gb of 36.000Gb
While tools like "heap" and "jps" shows another picture
free -h
total used free shared buff/cache available
Mem: 125Gi 102Gi 15Gi 118Mi 8.3Gi 22Gi
Swap: 0B 0B 0B
PS: when the memory grows above 33-35 GB, pod restarts
May be related to this Linux: Cannot allocate more than 32 GB/64 GB of memory in a single process due to virtual memory limit