0

I developed some appication in Java which is being initialized through init.d script. After running the application for a while I found out the following:

$cat /proc/[java_app_pid]/cmdline
java-Xmx256m... other options

$cat /proc/[java_app_pid]/status
...
VmHWM:    669176 kB
VmRSS:    560352 kB
...

From what I can see the whole resident size memory consumption is 560MB with HWM 669 MB for 256 MB heap. It looks like inefficient memory utilization (HWM 2.5 times more than heap size).

My application does not allocate any direct buffers (explicitly). It catches file-system events through NIO and processes them.

My first thought was that headers consumed the memory. But as documented here for 64-bit VM they consumed 8 bytes for each instance. Where they resides(heap/offheap) is unspecified in the source I linked.

I wanted to make memory dump through gdb, but I don't know the address space the heap/non-heap memory resides at. Can you advice some direction to move to investigate the problem?

St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • JVM itself obviously has some overhead. Did you try setting the heap to 512M or 1G and see how much RSS grows to? I suspect the ratio will quickly drop. – jingx May 21 '18 at 16:49
  • @jingx I tried to set -Xmx2g and the RSS was growing to about 2.7G – St.Antario May 21 '18 at 16:56
  • @jingx Right after the startup JVM consume about 30MB RSS. – St.Antario May 21 '18 at 17:20
  • Memory consumed by Java process is not limited by Java Heap. Don't forget about Metaspace, Code cache, Thread stacks, GC internal structures, JIT Compilers structures, Symbol tables, shared libraries and all other malloc'ed stuff for the purpose of JVM and the Class Library. – apangin May 21 '18 at 17:27
  • @apangin Is there a way to analyze the memory in some way? `jmap` does not seem to include this memory. Is gdb memory dump by address range the only way to go? – St.Antario May 21 '18 at 17:34
  • Well 2.7/2 isn't that bad, is it? The JVM is a native process, so you could apply whatever memory analysis to it just like you would any other process, but I don't see a lot you can do to reduce JVM's internal memory footprint. – jingx May 21 '18 at 17:40
  • 1
    Have a look at [NativeMemoryTracking](https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html) – apangin May 21 '18 at 17:42

0 Answers0