Quick revision
The short answer
We start the JVM with -XX:NativeMemoryTracking=summary or detail, since it cannot be turned on later, and run jcmd <pid> VM.native_memory summary to see reserved and committed memory per category: Java Heap, Class, Thread, Code, GC, Compiler, Internal, Symbol and others. Committed roughly corresponds to what counts toward RSS, and a baseline followed later by summary.diff shows which categories grow. NMT adds some overhead, more in detail mode, and it cannot see allocations made by native libraries outside the JVM or fragmentation in the allocator, so a gap between NMT and RSS points outside the JVM.
What to remember
In this answer, we used native memory tracking to explain why RSS exceeds the heap. We enabled it at startup, since it cannot be turned on later, read reserved and committed memory per category with jcmd VM.native_memory summary, and used a baseline and summary.diff to find the categories that grow, with detail mode for call sites. Committed roughly corresponds to RSS. NMT has some overhead, more in detail mode, and it cannot see native library allocations or allocator fragmentation, so a gap between NMT and RSS sends us to pmap and native allocation profilers.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We start the JVM with -XX:NativeMemoryTracking=summary or detail, since it cannot be turned on later, and run jcmd <pid> VM.native_memory summary to see reserved and committed memory per category: Java Heap, Class, Thread, Code, GC, Compiler, Internal, Symbol and others. Committed roughly corresponds to what counts toward RSS, and a baseline followed later by summary.diff shows which categories grow. NMT adds some overhead, more in detail mode, and it cannot see allocations made by native libraries outside the JVM or fragmentation in the allocator, so a gap between NMT and RSS points outside the JVM.
Why this question is asked
Resident memory larger than the heap is the normal state of a JVM, but when the gap is large or growing, it decides whether a container gets OOM killed. Native memory tracking is the JVM's own tool for explaining that gap, and knowing exactly what it can and cannot tell us saves a lot of wasted investigation. Interviewers ask this internals question to see whether we can use the tool step by step and also recognise when the answer lies outside it. In this answer, we will recap what RSS is, enable NMT and read a summary, use baselines and diffs to find growth, look at its overhead, and then go through its limits and the tools that fill them.
1A Quick Recap: RSS, Reserved and Committed
Resident set size, RSS, is the amount of physical memory a process currently occupies. It is what the kernel counts and what a container memory limit is compared against, more precisely the cgroup's memory usage, which also includes some page cache.
The JVM thinks about memory in two steps. Reserving means setting aside a range of virtual addresses, which costs almost nothing. Committing means asking the operating system to back part of that range with memory. Committed memory becomes resident when its pages are touched. So reserved is address space, committed is close to what the JVM uses, and RSS is what is actually in physical memory, usually close to committed but not always equal.
2Enabling NMT and Reading a Summary
NMT must be enabled when the JVM starts, because it has to record allocations from the very beginning; there is no way to turn it on in a running JVM. There are two levels: summary, which tracks totals per category, and detail, which also records the call sites that allocated memory.
Now we can explain most of RSS. The heap is 1,400 MB, and the other categories add about 430 MB committed, for a total of 1,830 MB. RSS is 1,960 MB, so about 130 MB is not explained by NMT. That remainder is worth remembering: it is the part we will need other tools for.
3Finding What Grows With a Baseline and a Diff
A single summary shows where memory is now. For a growing RSS we want to know which category grows, so we take a baseline soon after startup, once the service is warmed up, and compare later.
- Start with NativeMemoryTracking=summarycannot be enabled later
- Baseline after warmupjcmd
VM.native_memorybaseline - Hours later: summary.diffwhich categories grew?
- Does committed growth match RSS growth?YesFix the growing categoryNoLook outside the JVM: native libraries, allocator
4 steps in order. Play them, or step through them one at a time.
The diff answers the question directly. Here, 280 new threads appeared and Other grew by 250 MB, which in practice often means direct buffers, so we look for a component that creates threads and holds direct buffers, such as a client library creating a new connection pool repeatedly. With detail mode, detail.diff goes further and shows the allocation call sites that grew, which can point at the exact JVM or JDK code path.
Notice that the heap is unchanged. This is the typical pattern behind container OOM kills with a healthy heap, and NMT is how we prove it.
4What It Costs
NMT is not free. Every native allocation the JVM makes carries a small header for tracking, and the JVM updates counters on each allocation and free. In summary mode the cost is modest on recent JDKs; detail mode is noticeably more expensive, because it also captures the call stack of allocations. Older documentation quoted a performance drop of 5 to 10 percent, but the real figure depends heavily on the JDK version and the workload, so we measure it on our own service before enabling it widely.
In practice, many teams enable summary mode on a few canary instances permanently, or on all instances during an investigation, and use detail mode only for short, targeted sessions.
5Its Limits and How to See Past Them
NMT tracks memory the JVM itself allocates and attributes. It does not see memory allocated by native libraries through their own calls to malloc, for example a compression library, a database driver's native part, a cryptography provider or any JNI library. It also does not see fragmentation inside the C allocator: glibc's malloc keeps freed memory in arenas, often one per thread group, and may not return it to the operating system, so RSS stays high even after the JVM frees memory. And committed memory that was never touched is not resident, so NMT can occasionally show more committed than RSS for some regions.
So when RSS grows but NMT's committed total does not, the growth is outside NMT's view. Then we use operating-system tools: pmap -x <pid> or /proc/<pid>/smaps to see memory mappings and find large anonymous regions that do not match JVM structures, and a native allocation profiler, such as jemalloc's profiling or async-profiler's native memory mode in recent versions, to find who allocates. Setting MALLOC_ARENA_MAX to a small number such as 2 is a common way to reduce glibc arena fragmentation, and recent JDKs can trim the native heap periodically; check your version for the option.
| Memory | Visible in NMT? | Tool if not |
|---|---|---|
| Java heap, metaspace, code cache | yes | not needed |
| Thread stacks, GC structures | yes | not needed |
| Direct buffers via Unsafe | yes, usually under Other | not needed |
| Native libraries calling malloc | no | pmap, native allocation profiler |
| glibc arena fragmentation | no | pmap, MALLOC_ARENA_MAX, native heap trim |
| Memory-mapped files | no, as file mappings | pmap, smaps |
6Follow-up questions
Why does NMT have to be enabled at startup?
Because it works by recording every allocation as it happens, with a header attached to each tracked block. Memory allocated before tracking began would have no header and no record, so the JVM cannot start tracking halfway. It can, however, be shut down in a running JVM to stop the overhead.
Should committed memory always match RSS?
Not exactly. Committed pages that were never touched are not resident, and some memory, such as native library allocations and allocator overhead, is resident without being in NMT. So we use NMT for the JVM's own share and compare trends rather than expecting the totals to be equal.
7Conclusion
In this answer, we used native memory tracking to explain why RSS exceeds the heap. We enabled it at startup, since it cannot be turned on later, read reserved and committed memory per category with jcmd VM.native_memory summary, and used a baseline and summary.diff to find the categories that grow, with detail mode for call sites. Committed roughly corresponds to RSS. NMT has some overhead, more in detail mode, and it cannot see native library allocations or allocator fragmentation, so a gap between NMT and RSS sends us to pmap and native allocation profilers.
Open with
I would start the JVM with NativeMemoryTracking=summary, or detail if I need call sites, because it has to be enabled at startup; it cannot be attached later. Then jcmd pid VM.native_memory summary shows reserved and committed memory for each category: Java Heap, Class for metaspace, Thread, Code cache, GC, Compiler, Internal, Symbol, Other and so on.
Then, if they want more
Reserved is just address space; committed is what roughly counts toward RSS. So I add up committed and compare it with VmRSS: for example a 1.4 gigabyte heap plus 430 megabytes of native categories explains most of a 1.96 gigabyte RSS.
If RSS is growing, I take a baseline after warmup with VM.native_memory baseline, and hours later run summary.diff, which shows exactly which categories grew, like Thread plus 280 threads or Other plus 250 megabytes, often direct buffers. detail.diff can then show the call sites.
The limits: it adds overhead, modest in summary and more in detail mode, so I measure it. And it only sees the JVM's own allocations.
Memory malloced by native libraries through JNI, glibc arena fragmentation and file mappings are invisible, so if RSS grows while NMT stays flat, I switch to pmap or smaps and a native allocation profiler, and consider MALLOC_ARENA_MAX.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you use native memory tracking to explain why a JVM's resident memory is much...": https://scrivio-interview-library.netlify.app/java/jvm-diagnostics/e7843c170c/