Slow native memory leak over time of OpenJDK when G1 GC is used
Environment
- Red Hat Enterprise Linux (RHEL) 6
- Red Hat Enterprise Linux (RHEL) 7
- OpenJDK 1.7
- OpenJDK 1.8
Issue
- Slow native memory leak, Java heap is stable
- Only with G1 GC, not happen with other GC algorithms like Parallel or CMS
Resolution
Fixed in OpenJDK7u171(RHSA-2018:0349) and 8u144.
Upgrade to the next minor release of RHEL. On RHEL 6, an errata is available and you can upgrade the current OpenJDK by yum update java-1.8.0-openjdk.
Root Cause
There is a bug1 that interned strings (java.lang.String#intern()) are not garbage collected well when G1 GC is enabled.
Diagnostic Steps
A small reproducer, StringIntern.java, is attached in the JIRA ticket. By enabling the native memory tracking feature of OpenJDK, you can observe the Symbol usage becomes exceptionally high only with G1 GC.
$ javac StringIntern.java
$ java -XX:NativeMemoryTracking=detail -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:MetaspaceSize=100m -XX:MaxMetaspaceSize=100m -Xms256m -Xmx256m -XX:+UseConcMarkSweepGC StringInterner 2>&1 >cms.out
$ grep Symbol cms.out
- Symbol (reserved=26173KB, committed=26173KB)
$ java -XX:NativeMemoryTracking=detail -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:MetaspaceSize=100m -XX:MaxMetaspaceSize=100m -Xms256m -Xmx256m -XX:+UseG1GC StringInterner 2>&1 >g1.out
$ grep Symbol g1.out
- Symbol (reserved=241149KB, committed=241149KB)
On RHEL 6, the fix is already backported as This content is not included.BZ-1468473.
$ sudo yum update java-1.8.0-openjdk
$ rpm -q --changelog java-1.8.0-openjdk | head
* Fri Jul 14 2017 Andrew Hughes <gnu.andrew@redhat.com> - 1:1.8.0.141-3.b16
- Backport "8180048: Interned string and symbol table leak memory during parallel unlinking"
- Resolves: rhbz#1468473
...
$ java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)
$ java -XX:NativeMemoryTracking=detail -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:MetaspaceSize=100m -XX:MaxMetaspaceSize=100m -Xms256m -Xmx256m -XX:+UseG1GC StringInterner 2>&1 >g1.out
$ grep Symbol g1.out
- Symbol (reserved=36180KB, committed=36180KB)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.