2

env:jdk8
Garbage: g1

jvm paras: -Xms30G -Xmx30G -XX:MaxDirectMemorySize=1G -XX:MetaspaceSize=500m -XX:MaxMetaspaceSize=1G

The program runs for long times top command notice the Res is 60G or more。I want to know the reason for this problem. Who's ever had a problem like that? help me

1 Answers1

1

-Xmx is the maximum heap size. It is not the maximum process size. You are using other resources like threads, sockets, GUI, direct memory, shared libraries, metaspace, memory mapped files.

I would have said; Direct memory is the most likely, esp as it's maximum size is the same as the heap by default, however as @apangin points out you have set the maximum to 1 GB.

I don't know of an easy way to find how much direct memory is used, however on an Oracle JVM you can obtain java.nio.Bits#reservedMemory as it has the amount allocated currently.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    Direct memory usage can be tracked by the standard MBean `java.nio:type=BufferPool,name=[direct|mapped]`. However, in this particular question direct memory is unlikely to be a problem, since OP sets `-XX:MaxDirectMemorySize=1G`. – apangin Sep 19 '18 at 08:10
  • @apangin good spot – Peter Lawrey Sep 19 '18 at 08:16
  • 后来我查到glibc 2.12版本有几个Arena内存管理的Bug,可能导致参数设置不生效或生效后内存继续往上涨:Bug 799327 - MALLOC_ARENA_MAX=1 does not work in RHEL 6.2(glibc 2.12)Bug 20425 - unbalanced and poor utilization of memory in glibc arenas may cause memory bloat and subsequent OOMBug 11261 - malloc uses excessive memory for multi-threaded applications然后,我们考虑到将MALLOC_ARENA_MAX设置为4已经影响了一些Arena内存池管理上的一些性能,要继续使用MALLOC_ARENA_MAX参数,就需要升级glibc的版本,升级完还不确定高版本的glibc与其他包兼容性上有什么影响,毕竟是操作系统底层的包了,所以就直接使用了Google的tcmalloc替代操作系统自带的glibc管理内存。有资料显示,使用tcmalloc以后,Web Server的吞吐量得以提升(先尝试的jemalloc,但是启动后会影响操作系统命令的执行,所以,就用了tcmalloc): – smart.water Sep 25 '18 at 09:51