Reputation: 5298
I am trying to hunt the memory leak in Java Spring Boot app inside docker container.
Heap size of the app is limited like this:
java -XX:NativeMemoryTracking=summary -jar /app-0.1.jar -Xms256m -Xmx512m
Native memory diff looks like this:
./jcmd 7 VM.native_memory summary.diff
Native Memory Tracking:
Total: reserved=8295301KB +1728KB, committed=2794537KB +470172KB
Java Heap (reserved=6469632KB, committed=2245120KB +466944KB) (mmap: reserved=6469632KB, committed=2245120KB +466944KB) Class (reserved=1141581KB -9KB, committed=103717KB -9KB) (classes #16347 -86) (malloc=13133KB -9KB #23221 -306) (mmap: reserved=1128448KB, committed=90584KB) Thread (reserved=85596KB +999KB, committed=85596KB +999KB) (thread #84 +1) (stack: reserved=85220KB +1027KB, committed=85220KB +1027KB) (malloc=279KB +3KB #498 +6) (arena=97KB -31 #162 +2) Code (reserved=255078KB +32KB, committed=32454KB +228KB) (malloc=5478KB +32KB #8900 +80) (mmap: reserved=249600KB, committed=26976KB +196KB) GC (reserved=249066KB -2KB, committed=233302KB +1302KB) (malloc=12694KB -2KB #257 -75) (mmap: reserved=236372KB, committed=220608KB +1304KB) Compiler (reserved=227KB +10KB, committed=227KB +10KB) (malloc=96KB +10KB #807 +15) (arena=131KB #7) Internal (reserved=68022KB +720KB, committed=68022KB +720KB) (malloc=67990KB +720KB #21374 -287) (mmap: reserved=32KB, committed=32KB) Symbol (reserved=21938KB -11KB, committed=21938KB -11KB) (malloc=19436KB -11KB #197124 -188) (arena=2501KB #1) Native Memory Tracking (reserved=3962KB -12KB, committed=3962KB -12KB) (malloc=15KB #178 +1) (tracking overhead=3947KB -12KB) Arena Chunk (reserved=199KB, committed=199KB) (malloc=199KB)
After taking the heap dump:
./jmap -dump:live,format=b,file=/tmp/dump2.hprof 7
The heap Leak Suspects
report is quite small - 45MB:
The question:
why is Java Heap committed=2245120KB - almost 2GB? It's not aligned with -Xmx512m
nor with heap dump size taken with jmap
.
Upvotes: 1
Views: 644
Reputation: 5298
The answer is actually simple:
Params -Xms256m -Xmx512m
were passed in wrong place and therefore ignored by JVM. The correct order of params is like this:
java -XX:NativeMemoryTracking=summary -Xms256m -Xmx512m -jar /app-0.1.jar
Also, dump is much smaller than Java Heap committed
because only live objects were dumped, due to -dump:live
. After changing dump command to:
./jmap -dump:format=b,file=/tmp/dump2.hprof 7
the size of dump is very close to Java Heap committed
.
Upvotes: 1