为什么Java本地内存跟踪中的内部内存在增加?

16 浏览
0 Comments

为什么Java本地内存跟踪中的内部内存在增加?

我的应用程序运行在一个docker容器中,它使用scala,并使用\"OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)\",它的Xmx被设置为16GB,容器内存限制为24GB,在运行一段时间后容器被杀死:

Last State:         Terminated
  Reason:           OOMKilled
  Exit Code:        137

然而,在所有的48个节点中,在过去的两周中,我在日志中没有发现任何\"java.lang.OutOfMemoryError: Java heap space\"错误,所以不太可能是普通的堆OOM。

dmesg输出:

$ dmesg -l err,crit,alert,emerg
STDIN is not a terminal
[1647254.978515] Memory cgroup out of memory: Kill process 10924 (java) score 1652 or sacrifice child
[1647254.989138] Killed process 10924 (java) total-vm:34187148kB, anon-rss:24853120kB, file-rss:23904kB
[1655749.664871] Memory cgroup out of memory: Kill process 1969 (java) score 1652 or sacrifice child
[1655749.675513] Killed process 1969 (java) total-vm:35201940kB, anon-rss:24856624kB, file-rss:24120kB
[1655749.987605] Memory cgroup out of memory: Kill process 2799 (java) score 1656 or sacrifice child

然后我多次运行JCMD,直到它再次被杀死,数据看起来如下:

Native Memory Tracking:

Total: reserved=25505339KB, committed=25140947KB

- Java Heap (reserved=16777216KB, committed=16777216KB)

(mmap: reserved=16777216KB, committed=16777216KB)

  • Class (reserved=247996KB, committed=93500KB)

    (classes #14539)

    (malloc=2236KB #29794)

    (mmap: reserved=245760KB, committed=91264KB)

  • Thread (reserved=1013160KB, committed=1013160KB)

    (thread #1902)

    (stack: reserved=1003956KB, committed=1003956KB)

    (malloc=6240KB #9523)

    (arena=2964KB #3803)

  • Code (reserved=263255KB, committed=86131KB)

    (malloc=13655KB #20964)

    (mmap: reserved=249600KB, committed=72476KB)

  • GC (reserved=776174KB, committed=776174KB)

    (malloc=120814KB #164310)

    (mmap: reserved=655360KB, committed=655360KB)

  • Compiler (reserved=812KB, committed=812KB)

    (malloc=681KB #1823)

    (arena=131KB #3)

  • Internal (reserved=6366260KB, committed=6366256KB)

    (malloc=6366256KB #178778)

    (mmap: reserved=4KB, committed=0KB)

  • Symbol (reserved=18391KB, committed=18391KB)

    (malloc=16242KB #153138)

    (arena=2150KB #1)

  • Native Memory Tracking (reserved=9002KB, committed=9002KB)

    (malloc=186KB #2000)

    (tracking overhead=8816KB)

  • Arena Chunk (reserved=273KB, committed=273KB)

    (malloc=273KB)

  • Unknown (reserved=32800KB, committed=32KB)

    (mmap: reserved=32800KB, committed=32KB)

我注意到的一件事是这个部分:

Internal (reserved=6366260KB, committed=6366256KB)

它不断增长,导致总内存使用量超过了 24GB 的限制。

有没有人以前遇到过类似的问题? 有没有人知道这里的内部内存是什么,以及为什么它不断增长而不释放内存的原因?

admin 更改状态以发布 2023年5月24日
0
0 Comments

这不是你问题的答案,只是一种解决方法。

我曾观察到在运行java版本为“1.8.0_45”的docker容器中运行的JRuby中出现了同样的问题。解决方案是显式地调用垃圾收集。我绝对不知道为什么会有用,但在垃圾收集后,内部Java内存返回到了8MB。

0
0 Comments

最近我们的应用程序遇到了相同的问题。在我们的情况下,我们使用netty,并且netty分配了直接内存,在存在许多io连接时,Java本地内存跟踪中的内部内存增加。
\n最终我们使用了两个参数来限制本地内存。

-Dio.netty.maxDirectMemory=1073741824
-XX:MaxDirectMemorySize=1024m

0