ps v jvm_id to check memory usage - unix1998/technical_notes GitHub Wiki

The ps v <PID> command on a Linux system provides detailed information about the process with the given process ID (PID). The fields shown in the output can help you understand the memory usage of the process, including both Java heap and native memory.

Here's a breakdown of the key fields related to memory usage in the ps v <PID> output:

  • PID: Process ID of the process.
  • TTY: Terminal associated with the process.
  • STAT: Process state.
  • TIME: Total CPU time used by the process.
  • MAJFL: Major page faults, indicating the number of times the process has accessed memory that wasn't in RAM and had to be fetched from disk.
  • TRS: Text resident set size, the size of the text (code) segment currently in memory.
  • DRS: Data resident set size, the size of the data segment currently in memory.
  • RSS: Resident set size, the total memory occupied by the process in RAM. This includes the heap, stack, and any other memory segments.
  • %MEM: Percentage of physical memory used by the process.
  • COMMAND: Command that started the process.

Interpretation for JVM Memory

  1. RSS (Resident Set Size): This is the total amount of physical memory the process is using. For a Java process, it includes the Java heap, native memory used by the JVM, and memory used by native libraries.
  2. DRS (Data Resident Set Size): This represents the size of the data segment, which includes the heap and other dynamically allocated memory.
  3. TRS (Text Resident Set Size): This represents the size of the text (code) segment. This is typically less relevant for understanding JVM memory usage but indicates the size of the executable code in memory.
  4. MAJFL (Major Page Faults): High values here could indicate that the process is frequently accessing memory that is not currently in RAM, causing the system to fetch it from disk. This can affect performance but is not directly related to Java heap or native memory usage.

Example Analysis

Given the output:

 PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
3300 pts/1    Sl     2:02     36     3 7208088 1100480 14.3 /opt/jdk-11.0.16.1/bin/java
  • PID: 3300
  • RSS: 1100480 KB (~1.1 GB) - Total memory used by the JVM process.
  • DRS: 7208088 KB (~7.2 GB) - Size of the data segment, including the heap.
  • %MEM: 14.3 - The process uses 14.3% of the physical memory.

Conclusion

The ps v <PID> command provides useful information about the memory usage of a JVM process, including both Java heap and native memory. The RSS field gives you the total memory usage, while the DRS field indicates the size of the data segment. To get more detailed insights, especially for analyzing Java heap memory, you would still use tools like Eclipse MAT, while for native memory, tools like NMT or system-level monitoring tools would be more appropriate.

⚠️ **GitHub.com Fallback** ⚠️