Report short summary of memory utilization statistics.
Report details of memory utilization statistics.
Report details of slab utilization statistics.
Report virtual memory statistics.
Report virtual memory statistics iteratively (the example's sampling is 5 seconds.)
Report memory and swap space utilization statistics iteratively (the example's sampling is 5 seconds and, count is 10)
There is no easy or very reliable way to identify the amount of actual memory being used by an individual process or program or application because every process will be using multiple system maps from various libraries like glibc which will also be used by many other processes so the reported memory will include the mem utilised by these other buffer segments. Although we can get close enough to the actual memory utilisation by using the below methods.
But still there are few methods which can be used to give you some memory related data which can help you with your requirement.
RSS usage by using "ps" tool
ps displays information about a selection of the active processes. By default we get the below list of columns when ps is executed
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
Here RSS is Resident Set Size, the non-swapped physical memory used by process.
From the man page
For example I have amsHelper process
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2071 0.0 0.0 176508 11620 ? Ss Jul31 0:27 /sbin/amsHelper -f
As per the RSS, amsHelper is using ~11MB
VSZ usage by using "ps" tool
VSZ is Virtual Set Size, the total virtual memory size of the process i.e,the total amount of memory in swap and RAM.
From the man page
For my amsHelper process
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2071 0.0 0.0 176508 11620 ? Ss Jul31 0:27 /sbin/amsHelper -f
The VSZ size is ~172MB
VmData usage from the process status
VmData is calculated as the total address space usage (i.e. VmSize) with shared and stack pages subtracted.
For single thread process this can give more fruitful information.
How to check the number of thread used by a process?
You can use the below command to check the number of active threads per process
Threads: 1
Threads: 2527
Here as you see my "amsHelper" process is running on single thread while "java" process is running with 2527 threads
The VmData size for my amsHelper process is ~6MB
VmData: 6964 kB
memory usage per process using pmap
To get a more precise count of the memory consumed by a process, use the pmap command. "pmap" is another tool which reports memory usage per process or multiple processes separately which will help in tracking down the exact memory used by a process.
Using "-X" we can get more detailed output
2071: /sbin/amsHelper -f
Address Perm Offset Device Inode Size Rss Pss Referenced Anonymous Swap Locked Mapping
00400000 r-xp 00000000 fd:00 13936 1632 1032 1032 1032 0 0 0 amsHelper
00798000 r--p 00198000 fd:00 13936 4 4 4 4 4 0 0 amsHelper
00799000 rw-p 00199000 fd:00 13936 52 44 44 44 16 0 0 amsHelper
007a6000 rw-p 00000000 00:00 0 356 48 48 48 48 0 0
00fcc000 rw-p 00000000 00:00 0 6432 6352 6352 6352 6352 0 0 [heap]
7eff20739000 r-xp 00000000 fd:00 3132 48 28 1 28 0 0 0 libnss_files-2.17.so
7eff20745000 ---p 0000c000 fd:00 3132 2044 0 0 0 0 0 0 libnss_files-2.17.so
7eff20944000 r--p 0000b000 fd:00 3132 4 4 4 4 4 0 0 libnss_files-2.17.so
7eff20945000 rw-p 0000c000 fd:00 3132 4 4 4 4 4 0 0 libnss_files-2.17.so
7eff20946000 rw-p 00000000 00:00 0 24 0 0 0 0 0 0
7eff2094c000 r--p 00000000 fd:00 3158 103588 44 1 44 0 0 0 locale-archive
7eff26e75000 r-xp 00000000 fd:00 3144 28 12 0 12 0 0 0 librt-2.17.so
7eff26e7c000 ---p 00007000 fd:00 3144 2044 0 0 0 0 0 0 librt-2.17.so
7eff2707b000 r--p 00006000 fd:00 3144 4 4 4 4 4 0 0 librt-2.17.so
7eff2707c000 rw-p 00007000 fd:00 3144 4 4 4 4 4 0 0 librt-2.17.so
7eff2707d000 r-xp 00000000 fd:00 3554 16 8 0 8 0 0 0 libattr.so.1.1.0
7eff27081000 ---p 00004000 fd:00 3554 2044 0 0 0 0 0 0 libattr.so.1.1.0
7eff27280000 r--p 00003000 fd:00 3554 4 4 4 4 4 0 0 libattr.so.1.1.0
7eff27281000 rw-p 00004000 fd:00 3554 4 4 4 4 4 0 0 libattr.so.1.1.0
7eff27282000 r-xp 00000000 fd:00 3295 384 8 0 8 0 0 0 libpcre.so.1.2.0
7eff272e2000 ---p 00060000 fd:00 3295 2048 0 0 0 0 0 0 libpcre.so.1.2.0
7eff274e2000 r--p 00060000 fd:00 3295 4 4 4 4 4 0 0 libpcre.so.1.2.0
7eff274e3000 rw-p 00061000 fd:00 3295 4 4 4 4 4 0 0 libpcre.so.1.2.0
7eff274e4000 r-xp 00000000 fd:00 3157 232 156 29 156 0 0 0 libnspr4.so
7eff2751e000 ---p 0003a000 fd:00 3157 2044 0 0 0 0 0 0 libnspr4.so
7eff2771d000 r--p 00039000 fd:00 3157 4 4 4 4 4 0 0 libnspr4.so
7eff2771e000 rw-p 0003a000 fd:00 3157 8 8 8 8 8 0 0 libnspr4.so
7eff27720000 rw-p 00000000 00:00 0 8 4 4 4 4 0 0
7eff27722000 r-xp 00000000 fd:00 3160 12 8 1 8 0 0 0 libplds4.so
7eff27725000 ---p 00003000 fd:00 3160 2044 0 0 0 0 0 0 libplds4.so
7eff27924000 r--p 00002000 fd:00 3160 4 4 4 4 4 0 0 libplds4.so
7eff27925000 rw-p 00003000 fd:00 3160 4 4 4 4 4 0 0 libplds4.so
7eff27926000 r-xp 00000000 fd:00 3159 16 12 4 12 0 0 0 libplc4.so
7eff2792a000 ---p 00004000 fd:00 3159 2044 0 0 0 0 0 0 libplc4.so
7eff27b29000 r--p 00003000 fd:00 3159 4 4 4 4 4 0 0 libplc4.so
7eff27b2a000 rw-p 00004000 fd:00 3159 4 4 4 4 4 0 0 libplc4.so
7eff27b2b000 r-xp 00000000 fd:00 3345 152 124 61 124 0 0 0 libnssutil3.so
7eff27b51000 ---p 00026000 fd:00 3345 2044 0 0 0 0 0 0 libnssutil3.so
7eff27d50000 r--p 00025000 fd:00 3345 28 28 28 28 28 0 0 libnssutil3.so
7eff27d57000 rw-p 0002c000 fd:00 3345 4 4 4 4 4 0 0 libnssutil3.so
7eff27d58000 r-xp 00000000 fd:00 3142 88 16 0 16 0 0 0 libresolv-2.17.so
7eff27d6e000 ---p 00016000 fd:00 3142 2048 0 0 0 0 0 0 libresolv-2.17.so
7eff27f6e000 r--p 00016000 fd:00 3142 4 4 4 4 4 0 0 libresolv-2.17.so
7eff27f6f000 rw-p 00017000 fd:00 3142 4 4 4 4 4 0 0 libresolv-2.17.so
7eff27f70000 rw-p 00000000 00:00 0 8 0 0 0 0 0 0
7eff27f72000 r-xp 00000000 fd:00 3512 1748 660 660 660 0 0 0 libdb-5.3.so
7eff28127000 ---p 001b5000 fd:00 3512 2048 0 0 0 0 0 0 libdb-5.3.so
7eff28327000 r--p 001b5000 fd:00 3512 28 28 28 28 28 0 0 libdb-5.3.so
7eff2832e000 rw-p 001bc000 fd:00 3512 12 12 12 12 12 0 0 libdb-5.3.so
7eff28331000 r-xp 00000000 fd:00 3566 28 12 3 12 0 0 0 libacl.so.1.1.0
7eff28338000 ---p 00007000 fd:00 3566 2048 0 0 0 0 0 0 libacl.so.1.1.0
7eff28538000 r--p 00007000 fd:00 3566 4 4 4 4 4 0 0 libacl.so.1.1.0
7eff28539000 rw-p 00008000 fd:00 3566 4 4 4 4 4 0 0 libacl.so.1.1.0
7eff2853a000 r-xp 00000000 fd:00 3556 16 8 0 8 0 0 0 libcap.so.2.22
7eff2853e000 ---p 00004000 fd:00 3556 2044 0 0 0 0 0 0 libcap.so.2.22
7eff2873d000 r--p 00003000 fd:00 3556 4 4 4 4 4 0 0 libcap.so.2.22
7eff2873e000 rw-p 00004000 fd:00 3556 4 4 4 4 4 0 0 libcap.so.2.22
7eff2873f000 r-xp 00000000 fd:00 3306 144 40 1 40 0 0 0 libselinux.so.1
7eff28763000 ---p 00024000 fd:00 3306 2044 0 0 0 0 0 0 libselinux.so.1
7eff28962000 r--p 00023000 fd:00 3306 4 4 4 4 4 0 0 libselinux.so.1
7eff28963000 rw-p 00024000 fd:00 3306 4 4 4 4 4 0 0 libselinux.so.1
7eff28964000 rw-p 00000000 00:00 0 8 4 4 4 4 0 0
7eff28966000 r-xp 00000000 fd:00 3140 92 64 1 64 0 0 0 libpthread-2.17.so
7eff2897d000 ---p 00017000 fd:00 3140 2044 0 0 0 0 0 0 libpthread-2.17.so
7eff28b7c000 r--p 00016000 fd:00 3140 4 4 4 4 4 0 0 libpthread-2.17.so
7eff28b7d000 rw-p 00017000 fd:00 3140 4 4 4 4 4 0 0 libpthread-2.17.so
7eff28b7e000 rw-p 00000000 00:00 0 16 4 4 4 4 0 0
7eff28b82000 r-xp 00000000 fd:00 3120 8 8 0 8 0 0 0 libdl-2.17.so
7eff28b84000 ---p 00002000 fd:00 3120 2048 0 0 0 0 0 0 libdl-2.17.so
7eff28d84000 r--p 00002000 fd:00 3120 4 4 4 4 4 0 0 libdl-2.17.so
7eff28d85000 rw-p 00003000 fd:00 3120 4 4 4 4 4 0 0 libdl-2.17.so
7eff28d86000 r-xp 00000000 fd:00 3550 176 120 120 120 0 0 0 liblua-5.1.so
7eff28db2000 ---p 0002c000 fd:00 3550 2044 0 0 0 0 0 0 liblua-5.1.so
7eff28fb1000 r--p 0002b000 fd:00 3550 8 8 8 8 8 0 0 liblua-5.1.so
7eff28fb3000 rw-p 0002d000 fd:00 3550 4 4 4 4 4 0 0 liblua-5.1.so
7eff28fb4000 r-xp 00000000 fd:00 3412 148 16 0 16 0 0 0 liblzma.so.5.2.2
7eff28fd9000 ---p 00025000 fd:00 3412 2044 0 0 0 0 0 0 liblzma.so.5.2.2
7eff291d8000 r--p 00024000 fd:00 3412 4 4 4 4 4 0 0 liblzma.so.5.2.2
7eff291d9000 rw-p 00025000 fd:00 3412 4 4 4 4 4 0 0 liblzma.so.5.2.2
7eff291da000 r-xp 00000000 fd:00 3324 36 16 14 16 0 0 0 libpopt.so.0.0.0
7eff291e3000 ---p 00009000 fd:00 3324 2044 0 0 0 0 0 0 libpopt.so.0.0.0
7eff293e2000 r--p 00008000 fd:00 3324 4 4 4 4 4 0 0 libpopt.so.0.0.0
7eff293e3000 rw-p 00009000 fd:00 3324 4 4 4 4 4 0 0 libpopt.so.0.0.0
7eff293e4000 r-xp 00000000 fd:00 3506 92 16 0 16 0 0 0 libelf-0.168.so
7eff293fb000 ---p 00017000 fd:00 3506 2044 0 0 0 0 0 0 libelf-0.168.so
7eff295fa000 r--p 00016000 fd:00 3506 4 4 4 4 4 0 0 libelf-0.168.so
7eff295fb000 rw-p 00017000 fd:00 3506 4 4 4 4 4 0 0 libelf-0.168.so
7eff295fc000 r-xp 00000000 fd:00 3309 84 12 0 12 0 0 0 libz.so.1.2.7
7eff29611000 ---p 00015000 fd:00 3309 2044 0 0 0 0 0 0 libz.so.1.2.7
7eff29810000 r--p 00014000 fd:00 3309 4 4 4 4 4 0 0 libz.so.1.2.7
7eff29811000 rw-p 00015000 fd:00 3309 4 4 4 4 4 0 0 libz.so.1.2.7
7eff29812000 r-xp 00000000 fd:00 3415 60 8 0 8 0 0 0 libbz2.so.1.0.6
7eff29821000 ---p 0000f000 fd:00 3415 2044 0 0 0 0 0 0 libbz2.so.1.0.6
7eff29a20000 r--p 0000e000 fd:00 3415 4 4 4 4 4 0 0 libbz2.so.1.0.6
7eff29a21000 rw-p 0000f000 fd:00 3415 4 4 4 4 4 0 0 libbz2.so.1.0.6
7eff29a22000 r-xp 00000000 fd:00 8343 1156 520 428 520 0 0 0 libnss3.so
7eff29b43000 ---p 00121000 fd:00 8343 2048 0 0 0 0 0 0 libnss3.so
7eff29d43000 r--p 00121000 fd:00 8343 20 20 20 20 20 0 0 libnss3.so
7eff29d48000 rw-p 00126000 fd:00 8343 8 8 8 8 8 0 0 libnss3.so
7eff29d4a000 rw-p 00000000 00:00 0 8 8 8 8 8 0 0
7eff29d4c000 r-xp 00000000 fd:00 3114 1760 880 84 880 0 0 0 libc-2.17.so
7eff29f04000 ---p 001b8000 fd:00 3114 2048 0 0 0 0 0 0 libc-2.17.so
7eff2a104000 r--p 001b8000 fd:00 3114 16 16 16 16 16 0 0 libc-2.17.so
7eff2a108000 rw-p 001bc000 fd:00 3114 8 8 8 8 8 0 0 libc-2.17.so
7eff2a10a000 rw-p 00000000 00:00 0 20 20 20 20 20 0 0
7eff2a10f000 r-xp 00000000 fd:00 4783 48 32 32 32 0 0 0 libpci.so.3.5.1
7eff2a11b000 ---p 0000c000 fd:00 4783 2044 0 0 0 0 0 0 libpci.so.3.5.1
7eff2a31a000 r--p 0000b000 fd:00 4783 4 4 4 4 4 0 0 libpci.so.3.5.1
7eff2a31b000 rw-p 0000c000 fd:00 4783 4 4 4 4 4 0 0 libpci.so.3.5.1
7eff2a31c000 r-xp 00000000 fd:00 8584 388 220 220 220 0 0 0 librpm.so.3.2.2
7eff2a37d000 ---p 00061000 fd:00 8584 2044 0 0 0 0 0 0 librpm.so.3.2.2
7eff2a57c000 r--p 00060000 fd:00 8584 12 12 12 12 12 0 0 librpm.so.3.2.2
7eff2a57f000 rw-p 00063000 fd:00 8584 12 12 12 12 12 0 0 librpm.so.3.2.2
7eff2a582000 rw-p 00000000 00:00 0 4 4 4 4 4 0 0
7eff2a583000 r-xp 00000000 fd:00 8586 160 124 124 124 0 0 0 librpmio.so.3.2.2
7eff2a5ab000 ---p 00028000 fd:00 8586 2044 0 0 0 0 0 0 librpmio.so.3.2.2
7eff2a7aa000 r--p 00027000 fd:00 8586 8 8 8 8 8 0 0 librpmio.so.3.2.2
7eff2a7ac000 rw-p 00029000 fd:00 8586 8 8 8 8 8 0 0 librpmio.so.3.2.2
7eff2a7ae000 rw-p 00000000 00:00 0 8 4 4 4 4 0 0
7eff2a7b0000 r-xp 00000000 fd:00 3122 1028 64 2 64 0 0 0 libm-2.17.so
7eff2a8b1000 ---p 00101000 fd:00 3122 2044 0 0 0 0 0 0 libm-2.17.so
7eff2aab0000 r--p 00100000 fd:00 3122 4 4 4 4 4 0 0 libm-2.17.so
7eff2aab1000 rw-p 00101000 fd:00 3122 4 4 4 4 4 0 0 libm-2.17.so
7eff2aab2000 r-xp 00000000 fd:00 3107 132 120 2 120 0 0 0 ld-2.17.so
7eff2ac7a000 r--s 00000000 fd:00 276277 264 264 264 264 0 0 0 modules.dep
7eff2acbd000 rw-p 00000000 00:00 0 56 56 56 56 56 0 0
7eff2accb000 r--s 00000000 fd:00 132676 28 24 2 24 0 0 0 gconv-modules.cache
7eff2acd2000 rw-p 00000000 00:00 0 4 4 4 4 4 0 0
7eff2acd3000 r--p 00021000 fd:00 3107 4 4 4 4 4 0 0 ld-2.17.so
7eff2acd4000 rw-p 00022000 fd:00 3107 4 4 4 4 4 0 0 ld-2.17.so
7eff2acd5000 rw-p 00000000 00:00 0 4 4 4 4 4 0 0
7ffeccb5d000 rw-p 00000000 00:00 0 132 32 32 32 32 0 0 [stack]
7ffeccb7e000 r-xp 00000000 00:00 0 8 4 0 4 0 0 0 [vdso]
ffffffffff600000 r-xp 00000000 00:00 0 4 0 0 0 0 0 0 [vsyscall]
====== ===== ===== ========== ========= ==== ======
176512 11620 10026 11620 6912 0 0 KB
Here all the maps with no permissions are buffer segments and the one with read only permission will use address space and not the actual memory so can be ignored when you plan to calculate the memory usage of the process/application
Below is a small regex which can be used to calculate the RES memory of "amsHelper" process by excluding all the buffer segments
11.3477 MB
For my Java process
345.441 MB
I hope the article was useful.