I try to monitor the total memory allocated to my Java application (OpenJDK 11.0.4) by the OS (Linux Ubuntu 19.04).
I take two approches:
- Using the VmRSS size from
ps
orcat /proc/<pid>/status | grep VmRSS
- Using Java NativeMemoryTracking functionality with the following properties:
-XX:NativeMemoryTracking=summary -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics
and using the Total committed size.
The numbers retrieved from both approaches are always different (sometimes of a few megabytes ... sometimes a lot more).
What I understand is that the VmRSS size reported by the OS is the real memory used by the process but why does Java NTM reports a different value?
If I want to be able to monitor the Resident Set Size of a Java application, should I rely on the OS reported size (VmRSS) of can I use something inside the JVM (like NTM) ? Ideally I want to be able to monitor the RSS size of my Java application from itself ...