0

我正在尝试寻找 docker 容器内 Java Spring Boot 应用程序中的内存泄漏。

应用程序的堆大小限制如下:

java -XX:NativeMemoryTracking=summary -jar /app-0.1.jar -Xms256m -Xmx512m

本机内存差异如下所示:

 ./jcmd 7 VM.native_memory summary.diff

本机内存跟踪:

总计: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)

进行堆转储后:

./jmap -dump:live,format=b,file=/tmp/dump2.hprof 7

Leak Suspects报告非常小 - 45MB:

在此处输入图像描述

问题:为什么 Java 堆已提交=2245120KB - 几乎 2GB?它与-Xmx512m使用jmap.

4

1 回答 1

0

答案其实很简单:

参数-Xms256m -Xmx512m传递到错误的位置,因此被 JVM 忽略。正确的参数顺序是这样的:

java -XX:NativeMemoryTracking=summary -Xms256m -Xmx512m -jar /app-0.1.jar 

此外,Java Heap committed由于. _ -dump:live将转储命令更改为:

./jmap -dump:format=b,file=/tmp/dump2.hprof 7

转储的大小非常接近Java Heap committed

于 2022-02-24T11:34:25.783 回答