The difference in memory and RSS in a java process

I am launching a simple java process running on a jetty for which the top shows 2.9 g of RAM. The version of JDK used is 1.8.0_112.

enter image description here

Using Native Memory Tracking (jcmd) shows that total fixed memory is only 1.5 GB of memory

enter image description here

Also, the direct buffer pool size is very smaller, as reported by jvisualvm.

enter image description here

I am fully aware that the memory shown by NMT is a memory that should not be in RAM. In this case, the contribution of NMT memory to RES should be equal to 1.5 GB of RES memory.

In my case, the difference here is ~ 1.4G (RES shows 1.4G of additional memory), which cannot be attributed only to shared libs, jars. Can someone tell me how to find out what additional memory is and what tools can be used to check it?

I checked all existing related problems online / Stackoverflow, but could not find a suitable answer.

+5
source share
1 answer

pmap -X <pid> will show a detailed breakdown of RSS from an OS perspective.

NMT does not count memory allocated by native code other than the JVM, even if that memory is allocated by the standard Java class library, for example. using native ZipInputStream methods. See related question .

Another possible reason is malloc . The main memory drive rarely returns unused memory back to the OS. For example, if an application allocates 1 GB in small chunks using malloc and then frees all these chunks, from the point of view of the application there will be 1 GB of free memory, but the OS will probably consider this 1 GB in RSS. This memory is mainly owned by the malloc application pool and can be reused for future malloc calls.

Try alternative dispensers like jemalloc or tcmalloc . By the way, they both have a distribution profiler that can help in detecting memory leaks.

+1
source

Source: https://habr.com/ru/post/1276152/


All Articles