Search code examples
javamemory-managementgarbage-collectionoff-heap

JVM memory usage more than reported by OS


I have a JVM which reports committed heap memory as around 8GB (Other sections should be over and above this). But my OS shows memory usage as around 5GB. I understand the memory usage can be more than the committed memory due to non-heap, metaspace etc, but how is it possible that the usage is lesser than reported by the jvm?

The output of free shows memory usage of 5.5GB

#free -m
          total        used        free      shared  buff/cache   available
Mem:          24115        5536       16355          10        2223       18209
Swap:             0           0           0

Output of Native Memory Tracker (NMT) shows reserved memory as ~ 11 GB

#jcmd <pid> VM.native_memory


Total: reserved=12904933KB, committed=11679661KB
-                 Java Heap (reserved=8388608KB, committed=8388608KB)
                            (mmap: reserved=8388608KB, committed=8388608KB)

-                     Class (reserved=1161913KB, committed=127417KB)
                            (classes #20704)
                            (malloc=2745KB #33662)
                            (mmap: reserved=1159168KB, committed=124672KB)

-                    Thread (reserved=2585224KB, committed=2585224KB)
                            (thread #2505)
                            (stack: reserved=2574004KB, committed=2574004KB)
                            (malloc=8286KB #12532)
                            (arena=2934KB #5004)

-                      Code (reserved=264623KB, committed=90231KB)
                            (malloc=15023KB #22507)
                            (mmap: reserved=249600KB, committed=75208KB)

-                        GC (reserved=378096KB, committed=378096KB)
                            (malloc=34032KB #45794)
                            (mmap: reserved=344064KB, committed=344064KB)

-                  Compiler (reserved=776KB, committed=776KB)
                            (malloc=645KB #1914)
                            (arena=131KB #7)

-                  Internal (reserved=53892KB, committed=53892KB)
                            (malloc=53860KB #67113)
                            (mmap: reserved=32KB, committed=32KB)

-                    Symbol (reserved=26569KB, committed=26569KB)
                            (malloc=22406KB #204673)
                            (arena=4163KB #1)

-    Native Memory Tracking (reserved=6756KB, committed=6756KB)
                            (malloc=494KB #6248)
                            (tracking overhead=6262KB)

-               Arena Chunk (reserved=11636KB, committed=11636KB)
                            (malloc=11636KB)

-                   Tracing (reserved=10456KB, committed=10456KB)
                            (malloc=10456KB #787)

-                   Unknown (reserved=16384KB, committed=0KB)
                            (mmap: reserved=16384KB, committed=0KB)

OS - Debian 9

Java -

java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

I have read through some awesome answers like this one which explains NMT very well, but it doesn't address this issue. I would like to understand how this is possible.


Solution

  • Duplicate of Why does a JVM report more committed memory than the linux process resident set size? This pertains to the difference between Reserved / Committed / Resident memory as explained in the above answer.

    Closing this question.