How to find and analyze memory usage of a process?
7:56 PM
pmap reports memory map of a process on
Linux. It helps to analyze how the process memory is distributed for any
given pid, process.
Let us first examine a process using ps command:
[root@unknown000c294e077b ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2769 0.0 0.2 15540 2612 ? Sl 09:40 0:00 /usr/sbin/vmtoolsd
Two of the command outputs are VSZ and RSS, which stand for "virtual set size" and "resident set size". RSS shows how much 'physical memory' has been allocated to the process while VSZ tells us how much virtual memory(physical+swap) the process has marked for allocation. The values of RSS and VSZ includes space used by all shared libraries used by the process. The implication of this is that shared libraries count in full towards the size of a given process. Therefore; these values can be misleading when we try to find out the memory used by a process.
Now, let us use pmap to analyze the memory map of the process 2769. Below is the excerpt of the command
[root@unknown000c294e077b ~]# pmap -d 2769
2769: /usr/sbin/vmtoolsd
Address Kbytes Mode Offset Device Mapping
00110000 52 r-x-- 0000000000000000 0fd:00000 libproc-3.2.7.so
0011d000 4 rwx-- 000000000000c000 0fd:00000 libproc-3.2.7.so
0011e000 76 rwx-- 000000000011e000 000:00000 [ anon ]
00131000 816 r-x-- 0000000000000000 0fd:00000 libglib-2.0.so.0
001fd000 4 rwx-- 00000000000cb000 0fd:00000 libglib-2.0.so.0
001fe000 24 r-x-- 0000000000000000 0fd:00000 libvmtoolsd.so
00204000 4 rwx-- 0000000000005000 0fd:00000 libvmtoolsd.so
00205000 16 r-x-- 0000000000000000 0fd:00000 libguestInfo.so
00209000 4 rwx-- 0000000000003000 0fd:00000 libguestInfo.so
Note the last line of the command output:
mapped: 15540K writeable/private: 11348K shared: 28K
Mapped - Total amount of memory mapped to files used in the process. Same value as VSZ (virtual set size) found from ps command output
Writeable/private - The amount of private address space this process is taking. This is calculated after factoring out the memory used by shared libraries
Shared - The amount of address space this process is sharing with others.
So, in this example the memory consumed by process 2769 is 11348K. This is based on the assumption that all of the shared libraries were already loaded.
Let us first examine a process using ps command:
[root@unknown000c294e077b ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2769 0.0 0.2 15540 2612 ? Sl 09:40 0:00 /usr/sbin/vmtoolsd
Two of the command outputs are VSZ and RSS, which stand for "virtual set size" and "resident set size". RSS shows how much 'physical memory' has been allocated to the process while VSZ tells us how much virtual memory(physical+swap) the process has marked for allocation. The values of RSS and VSZ includes space used by all shared libraries used by the process. The implication of this is that shared libraries count in full towards the size of a given process. Therefore; these values can be misleading when we try to find out the memory used by a process.
Now, let us use pmap to analyze the memory map of the process 2769. Below is the excerpt of the command
[root@unknown000c294e077b ~]# pmap -d 2769
2769: /usr/sbin/vmtoolsd
Address Kbytes Mode Offset Device Mapping
00110000 52 r-x-- 0000000000000000 0fd:00000 libproc-3.2.7.so
0011d000 4 rwx-- 000000000000c000 0fd:00000 libproc-3.2.7.so
0011e000 76 rwx-- 000000000011e000 000:00000 [ anon ]
00131000 816 r-x-- 0000000000000000 0fd:00000 libglib-2.0.so.0
001fd000 4 rwx-- 00000000000cb000 0fd:00000 libglib-2.0.so.0
001fe000 24 r-x-- 0000000000000000 0fd:00000 libvmtoolsd.so
00204000 4 rwx-- 0000000000005000 0fd:00000 libvmtoolsd.so
00205000 16 r-x-- 0000000000000000 0fd:00000 libguestInfo.so
00209000 4 rwx-- 0000000000003000 0fd:00000 libguestInfo.so
Note the last line of the command output:
mapped: 15540K writeable/private: 11348K shared: 28K
Mapped - Total amount of memory mapped to files used in the process. Same value as VSZ (virtual set size) found from ps command output
Writeable/private - The amount of private address space this process is taking. This is calculated after factoring out the memory used by shared libraries
Shared - The amount of address space this process is sharing with others.
So, in this example the memory consumed by process 2769 is 11348K. This is based on the assumption that all of the shared libraries were already loaded.
0 comments