0

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

top shell command output

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

trincot
  • 317,000
  • 35
  • 244
  • 286

1 Answers1

0

Solved. Just add this JVM params

-XX:+UseContainerSupport -XX:MaxRAMPercentage=100

and also change the memory calc function to

log.info("RAM used {} of {} (max {})", FileUtils.byteCountToDisplaySize(memory),
            FileUtils.byteCountToDisplaySize(runtime.totalMemory()),
            FileUtils.byteCountToDisplaySize(runtime.maxMemory()));