New OpenJDK setting for better memory allocation.

Jbn1233
1 min readOct 3, 2021

Since -XX:InitialRAMFraction, -XX:MaxRAMFraction, and -XX:MinRAMFraction have been deprecated. Now we changed to

  • -XX:InitialRAMPercentage
  • -XX:MaxRAMPercentage
  • -XX:MinRAMPercentage

Example:

$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment Corretto-8.252.09.1 (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM Corretto-8.252.09.1 (build 25.252-b09, mixed mode)
$ free -m
total used free shared buff/cache available
Mem: 3921 462 851 6 2608 3170
Swap: 4091 10 4081
$ java -XX:+PrintFlagsFinal -XX:MaxRAMPercentage=10.0 -version 2>&1 | grep MaxHeapSize
uintx MaxHeapSize := 413138944 {product}
$ java -XX:+PrintFlagsFinal -XX:MaxRAMPercentage=50.0 -version 2>&1 | grep MaxHeapSize
uintx MaxHeapSize := 2057306112 {product}
$ java -XX:+PrintFlagsFinal -XX:MaxRAMPercentage=100.0 -version 2>&1 | grep MaxHeapSize
uintx MaxHeapSize := 4112515072 {product}

Use MaxRAMPercentage=100.0 is such a bad idea , need a free space for NoneHeap too.

Example:

Deployment

containers:
- env:
- name: JAVA_OPTS
value: -XX:InitialRAMPercentage=80.0 -XX:MaxRAMPercentage=80.0 -XX:MinRAMPercentage=80.0
image: tomcat:8-jdk8-corretto
imagePullPolicy: IfNotPresent
name: tomcat
resources:
limits:
memory: 1000Mi

Note:

NGCMX: Maximum new generation capacity (kB).
OGCMX: Maximum old generation capacity (kB).

--

--

Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |