Below article is tested and validated on Red Hat Enterprise Linux 7.
There is no way to know how much swap space is used by a process in kernel versions prior to version 2.6.18-128.el5 (RHEL 5 update 3). So in any prior RHEL versions (all of RHEL 3, RHEL 4, and RHEL 5 up to and including RHEL 5 update 2) the necessary kernel code for determining how much swap space is used by individual processes is not present
Using the below tool we only can know the total, used and available swap memory
total used free shared buff/cache available
Mem: 128816 10014 117010 126 1791 117822
Swap: 4091 1821 2270
But it does not gives any information on the swap memory usage per process or application
Method 1
We have 'top' utility which can be used as the first tool to get the swap utilisation value per process. By default 'top' does not shows the SWAP utilisation so you will need to add additional field "SWAP" which will then show this value.
'top' natively shows this information by using this formula:
Raw
VIRT = SWAP + RES or equal
SWAP = VIRT - RES
The output would look like something below
6735 dbmrun 20 0 19.324g 3.178g 4868 S 0.7 2.5 151:06.86 java 364288
2216 ssrun 20 0 24.737g 1.639g 2588 S 0.0 1.3 24:59.10 jsvc 211668
2214 ne3suser 20 0 12.719g 1.055g 5672 S 0.3 0.8 22:04.87 jsvc 284028
4162 ne3suser 20 0 14.428g 822776 5280 S 0.0 0.6 15:10.43 jsvc 958204
2215 ssrun 20 0 7011772 344136 6024 S 0.0 0.3 16:28.47 jsvc 24996
2217 ssrun 20 0 6315572 188004 4596 S 0.0 0.1 12:24.31 jsvc 19128
2168 postgres 20 0 280636 35828 35516 S 0.0 0.0 0:23.95 postgres 796
757 root 20 0 53220 16856 16532 S 0.0 0.0 0:22.14 systemd-journal 0
1954 root 20 0 568732 11504 400 S 0.0 0.0 1:05.69 tuned 1676
1143 root 20 0 359164 10224 8812 S 0.0 0.0 0:35.86 rsyslogd 216
2010 root 20 0 188204 8284 780 S 0.0 0.0 1:25.03 amsHelper 4592
Here as you see a new column is added in the last which shows us the SWAP memory usage.
Method 2
We can also check this value from the per process status which will give value similar to what we got with 'top' utility
For example if I wish to get swap usage detaul for 'amsHelper' process
VmSwap: 4592 kB
If the process has multiple PID associated then below command will help
VmSwap: 1560 kB
VmSwap: 1068 kB
VmSwap: 916 kB
VmSwap: 928 kB
VmSwap: 960 kB
VmSwap: 856 kB
VmSwap: 1020 kB
VmSwap: 944 kB
VmSwap: 1012 kB
VmSwap: 756 kB
VmSwap: 1024 kB
VmSwap: 816 kB
VmSwap: 1132 kB
VmSwap: 900 kB
VmSwap: 884 kB
VmSwap: 864 kB
VmSwap: 888 kB
VmSwap: 796 kB
To calculate the total
17324
Method 3
You can also use 'pmap' to get the detail of the swap memory usage for a process. This value will again be similar to what we calculated above
For example to get the swap usage for 'amsHelper'
2010: /sbin/amsHelper -f
Address Perm Offset Device Inode Size Rss Pss Referenced Anonymous Swap Locked Mapping
00400000 r-xp 00000000 fd:00 13670 1632 408 408 408 0 0 0 amsHelper
00798000 r--p 00198000 fd:00 13670 4 4 4 4 4 0 0 amsHelper
00799000 rw-p 00199000 fd:00 13670 52 16 16 12 16 0 0 amsHelper
007a6000 rw-p 00000000 00:00 0 356 32 32 32 32 16 0
021c6000 rw-p 00000000 00:00 0 11584 7280 7280 7268 7280 4240 0 [heap]
7f4177075000 r-xp 00000000 fd:00 3119 48 0 0 0 0 0 0 libnss_files-2.17.so
7f4177081000 ---p 0000c000 fd:00 3119 2044 0 0 0 0 0 0 libnss_files-2.17.so
7f4177280000 r--p 0000b000 fd:00 3119 4 0 0 0 0 4 0 libnss_files-2.17.so
7f4177281000 rw-p 0000c000 fd:00 3119 4 0 0 0 0 4 0 libnss_files-2.17.so
7f4177282000 rw-p 00000000 00:00 0 24 0 0 0 0 0 0
7f4177288000 r-xp 00000000 fd:00 3123 40 0 0 0 0 0 0 libnss_nis-2.17.so
7f4177292000 ---p 0000a000 fd:00 3123 2048 0 0 0 0 0 0 libnss_nis-2.17.so
7f4177492000 r--p 0000a000 fd:00 3123 4 0 0 0 0 4 0 libnss_nis-2.17.so
7f4177493000 rw-p 0000b000 fd:00 3123 4 0 0 0 0 4 0 libnss_nis-2.17.so
7f4177494000 r-xp 00000000 fd:00 3111 88 0 0 0 0 0 0 libnsl-2.17.so
7f41774aa000 ---p 00016000 fd:00 3111 2044 0 0 0 0 0 0 libnsl-2.17.so
7f41776a9000 r--p 00015000 fd:00 3111 4 0 0 0 0 4 0 libnsl-2.17.so
7f41776aa000 rw-p 00016000 fd:00 3111 4 0 0 0 0 4 0 libnsl-2.17.so
7f41776ab000 rw-p 00000000 00:00 0 8 0 0 0 0 0 0
7f41776ad000 r-xp 00000000 fd:00 3113 32 0 0 0 0 0 0 libnss_compat-2.17.so
7f41776b5000 ---p 00008000 fd:00 3113 2048 0 0 0 0 0 0 libnss_compat-2.17.so
7f41778b5000 r--p 00008000 fd:00 3113 4 0 0 0 0 4 0 libnss_compat-2.17.so
7f41778b6000 rw-p 00009000 fd:00 3113 4 0 0 0 0 4 0 libnss_compat-2.17.so
7f41778b7000 r--p 00000000 fd:00 132689 103588 8 0 8 0 0 0 locale-archive
7f417dde0000 r-xp 00000000 fd:00 3131 28 0 0 0 0 0 0 librt-2.17.so
7f417dde7000 ---p 00007000 fd:00 3131 2044 0 0 0 0 0 0 librt-2.17.so
7f417dfe6000 r--p 00006000 fd:00 3131 4 0 0 0 0 4 0 librt-2.17.so
7f417dfe7000 rw-p 00007000 fd:00 3131 4 0 0 0 0 4 0 librt-2.17.so
7f417dfe8000 r-xp 00000000 fd:00 3531 16 0 0 0 0 0 0 libattr.so.1.1.0
7f417dfec000 ---p 00004000 fd:00 3531 2044 0 0 0 0 0 0 libattr.so.1.1.0
7f417e1eb000 r--p 00003000 fd:00 3531 4 0 0 0 0 4 0 libattr.so.1.1.0
7f417e1ec000 rw-p 00004000 fd:00 3531 4 0 0 0 0 4 0 libattr.so.1.1.0
7f417e1ed000 r-xp 00000000 fd:00 3281 384 0 0 0 0 0 0 libpcre.so.1.2.0
7f417e24d000 ---p 00060000 fd:00 3281 2048 0 0 0 0 0 0 libpcre.so.1.2.0
7f417e44d000 r--p 00060000 fd:00 3281 4 0 0 0 0 4 0 libpcre.so.1.2.0
7f417e44e000 rw-p 00061000 fd:00 3281 4 0 0 0 0 4 0 libpcre.so.1.2.0
7f417e44f000 r-xp 00000000 fd:00 3144 232 0 0 0 0 0 0 libnspr4.so
7f417e489000 ---p 0003a000 fd:00 3144 2044 0 0 0 0 0 0 libnspr4.so
7f417e688000 r--p 00039000 fd:00 3144 4 0 0 0 0 4 0 libnspr4.so
7f417e689000 rw-p 0003a000 fd:00 3144 8 0 0 0 0 8 0 libnspr4.so
7f417e68b000 rw-p 00000000 00:00 0 8 0 0 0 0 4 0
7f417e68d000 r-xp 00000000 fd:00 3146 12 0 0 0 0 0 0 libplds4.so
7f417e690000 ---p 00003000 fd:00 3146 2044 0 0 0 0 0 0 libplds4.so
7f417e88f000 r--p 00002000 fd:00 3146 4 0 0 0 0 4 0 libplds4.so
7f417e890000 rw-p 00003000 fd:00 3146 4 0 0 0 0 4 0 libplds4.so
7f417e891000 r-xp 00000000 fd:00 3145 16 0 0 0 0 0 0 libplc4.so
7f417e895000 ---p 00004000 fd:00 3145 2044 0 0 0 0 0 0 libplc4.so
7f417ea94000 r--p 00003000 fd:00 3145 4 0 0 0 0 4 0 libplc4.so
7f417ea95000 rw-p 00004000 fd:00 3145 4 0 0 0 0 4 0 libplc4.so
7f417ea96000 r-xp 00000000 fd:00 3328 152 0 0 0 0 0 0 libnssutil3.so
7f417eabc000 ---p 00026000 fd:00 3328 2044 0 0 0 0 0 0 libnssutil3.so
7f417ecbb000 r--p 00025000 fd:00 3328 28 0 0 0 0 28 0 libnssutil3.so
7f417ecc2000 rw-p 0002c000 fd:00 3328 4 0 0 0 0 4 0 libnssutil3.so
7f417ecc3000 r-xp 00000000 fd:00 3129 88 0 0 0 0 0 0 libresolv-2.17.so
7f417ecd9000 ---p 00016000 fd:00 3129 2048 0 0 0 0 0 0 libresolv-2.17.so
7f417eed9000 r--p 00016000 fd:00 3129 4 0 0 0 0 4 0 libresolv-2.17.so
7f417eeda000 rw-p 00017000 fd:00 3129 4 0 0 0 0 4 0 libresolv-2.17.so
7f417eedb000 rw-p 00000000 00:00 0 8 0 0 0 0 0 0
7f417eedd000 r-xp 00000000 fd:00 3489 1748 0 0 0 0 0 0 libdb-5.3.so
7f417f092000 ---p 001b5000 fd:00 3489 2048 0 0 0 0 0 0 libdb-5.3.so
7f417f292000 r--p 001b5000 fd:00 3489 28 0 0 0 0 28 0 libdb-5.3.so
7f417f299000 rw-p 001bc000 fd:00 3489 12 0 0 0 0 12 0 libdb-5.3.so
7f417f29c000 r-xp 00000000 fd:00 3543 28 0 0 0 0 0 0 libacl.so.1.1.0
7f417f2a3000 ---p 00007000 fd:00 3543 2048 0 0 0 0 0 0 libacl.so.1.1.0
7f417f4a3000 r--p 00007000 fd:00 3543 4 4 4 0 4 0 0 libacl.so.1.1.0
7f417f4a4000 rw-p 00008000 fd:00 3543 4 4 4 0 4 0 0 libacl.so.1.1.0
7f417f4a5000 r-xp 00000000 fd:00 3533 16 0 0 0 0 0 0 libcap.so.2.22
7f417f4a9000 ---p 00004000 fd:00 3533 2044 0 0 0 0 0 0 libcap.so.2.22
7f417f6a8000 r--p 00003000 fd:00 3533 4 0 0 0 0 4 0 libcap.so.2.22
7f417f6a9000 rw-p 00004000 fd:00 3533 4 0 0 0 0 4 0 libcap.so.2.22
7f417f6aa000 r-xp 00000000 fd:00 3280 144 0 0 0 0 0 0 libselinux.so.1
7f417f6ce000 ---p 00024000 fd:00 3280 2044 0 0 0 0 0 0 libselinux.so.1
7f417f8cd000 r--p 00023000 fd:00 3280 4 0 0 0 0 4 0 libselinux.so.1
7f417f8ce000 rw-p 00024000 fd:00 3280 4 0 0 0 0 4 0 libselinux.so.1
7f417f8cf000 rw-p 00000000 00:00 0 8 0 0 0 0 4 0
7f417f8d1000 r-xp 00000000 fd:00 3127 92 40 0 40 0 0 0 libpthread-2.17.so
7f417f8e8000 ---p 00017000 fd:00 3127 2044 0 0 0 0 0 0 libpthread-2.17.so
7f417fae7000 r--p 00016000 fd:00 3127 4 0 0 0 0 4 0 libpthread-2.17.so
7f417fae8000 rw-p 00017000 fd:00 3127 4 0 0 0 0 4 0 libpthread-2.17.so
7f417fae9000 rw-p 00000000 00:00 0 16 0 0 0 0 4 0
7f417faed000 r-xp 00000000 fd:00 3107 8 0 0 0 0 0 0 libdl-2.17.so
7f417faef000 ---p 00002000 fd:00 3107 2048 0 0 0 0 0 0 libdl-2.17.so
7f417fcef000 r--p 00002000 fd:00 3107 4 4 4 0 4 0 0 libdl-2.17.so
7f417fcf0000 rw-p 00003000 fd:00 3107 4 4 4 0 4 0 0 libdl-2.17.so
7f417fcf1000 r-xp 00000000 fd:00 3527 176 0 0 0 0 0 0 liblua-5.1.so
7f417fd1d000 ---p 0002c000 fd:00 3527 2044 0 0 0 0 0 0 liblua-5.1.so
7f417ff1c000 r--p 0002b000 fd:00 3527 8 4 4 0 4 4 0 liblua-5.1.so
7f417ff1e000 rw-p 0002d000 fd:00 3527 4 4 4 0 4 0 0 liblua-5.1.so
7f417ff1f000 r-xp 00000000 fd:00 3389 148 0 0 0 0 0 0 liblzma.so.5.2.2
7f417ff44000 ---p 00025000 fd:00 3389 2044 0 0 0 0 0 0 liblzma.so.5.2.2
7f4180143000 r--p 00024000 fd:00 3389 4 4 4 0 4 0 0 liblzma.so.5.2.2
7f4180144000 rw-p 00025000 fd:00 3389 4 4 4 0 4 0 0 liblzma.so.5.2.2
7f4180145000 r-xp 00000000 fd:00 3307 36 0 0 0 0 0 0 libpopt.so.0.0.0
7f418014e000 ---p 00009000 fd:00 3307 2044 0 0 0 0 0 0 libpopt.so.0.0.0
7f418034d000 r--p 00008000 fd:00 3307 4 4 4 0 4 0 0 libpopt.so.0.0.0
7f418034e000 rw-p 00009000 fd:00 3307 4 4 4 0 4 0 0 libpopt.so.0.0.0
7f418034f000 r-xp 00000000 fd:00 3483 92 0 0 0 0 0 0 libelf-0.168.so
7f4180366000 ---p 00017000 fd:00 3483 2044 0 0 0 0 0 0 libelf-0.168.so
7f4180565000 r--p 00016000 fd:00 3483 4 4 4 0 4 0 0 libelf-0.168.so
7f4180566000 rw-p 00017000 fd:00 3483 4 4 4 0 4 0 0 libelf-0.168.so
7f4180567000 r-xp 00000000 fd:00 3293 84 0 0 0 0 0 0 libz.so.1.2.7
7f418057c000 ---p 00015000 fd:00 3293 2044 0 0 0 0 0 0 libz.so.1.2.7
7f418077b000 r--p 00014000 fd:00 3293 4 4 4 0 4 0 0 libz.so.1.2.7
7f418077c000 rw-p 00015000 fd:00 3293 4 4 4 0 4 0 0 libz.so.1.2.7
7f418077d000 r-xp 00000000 fd:00 3392 60 0 0 0 0 0 0 libbz2.so.1.0.6
7f418078c000 ---p 0000f000 fd:00 3392 2044 0 0 0 0 0 0 libbz2.so.1.0.6
7f418098b000 r--p 0000e000 fd:00 3392 4 4 4 0 4 0 0 libbz2.so.1.0.6
7f418098c000 rw-p 0000f000 fd:00 3392 4 4 4 0 4 0 0 libbz2.so.1.0.6
7f418098d000 r-xp 00000000 fd:00 8210 1156 0 0 0 0 0 0 libnss3.so
7f4180aae000 ---p 00121000 fd:00 8210 2048 0 0 0 0 0 0 libnss3.so
7f4180cae000 r--p 00121000 fd:00 8210 20 4 4 0 4 16 0 libnss3.so
7f4180cb3000 rw-p 00126000 fd:00 8210 8 4 4 0 4 4 0 libnss3.so
7f4180cb5000 rw-p 00000000 00:00 0 8 0 0 0 0 8 0
7f4180cb7000 r-xp 00000000 fd:00 3101 1760 304 10 304 0 0 0 libc-2.17.so
7f4180e6f000 ---p 001b8000 fd:00 3101 2048 0 0 0 0 0 0 libc-2.17.so
7f418106f000 r--p 001b8000 fd:00 3101 16 8 8 8 8 8 0 libc-2.17.so
7f4181073000 rw-p 001bc000 fd:00 3101 8 8 8 8 8 0 0 libc-2.17.so
7f4181075000 rw-p 00000000 00:00 0 20 8 8 8 8 12 0
7f418107a000 r-xp 00000000 fd:00 4599 48 0 0 0 0 0 0 libpci.so.3.5.1
7f4181086000 ---p 0000c000 fd:00 4599 2044 0 0 0 0 0 0 libpci.so.3.5.1
7f4181285000 r--p 0000b000 fd:00 4599 4 4 4 0 4 0 0 libpci.so.3.5.1
7f4181286000 rw-p 0000c000 fd:00 4599 4 4 4 0 4 0 0 libpci.so.3.5.1
7f4181287000 r-xp 00000000 fd:00 8422 388 0 0 0 0 0 0 librpm.so.3.2.2
7f41812e8000 ---p 00061000 fd:00 8422 2044 0 0 0 0 0 0 librpm.so.3.2.2
7f41814e7000 r--p 00060000 fd:00 8422 12 4 4 0 4 8 0 librpm.so.3.2.2
7f41814ea000 rw-p 00063000 fd:00 8422 12 4 4 0 4 8 0 librpm.so.3.2.2
7f41814ed000 rw-p 00000000 00:00 0 4 0 0 0 0 4 0
7f41814ee000 r-xp 00000000 fd:00 8424 160 0 0 0 0 0 0 librpmio.so.3.2.2
7f4181516000 ---p 00028000 fd:00 8424 2044 0 0 0 0 0 0 librpmio.so.3.2.2
7f4181715000 r--p 00027000 fd:00 8424 8 4 4 0 4 4 0 librpmio.so.3.2.2
7f4181717000 rw-p 00029000 fd:00 8424 8 4 4 0 4 4 0 librpmio.so.3.2.2
7f4181719000 rw-p 00000000 00:00 0 8 0 0 0 0 4 0
7f418171b000 r-xp 00000000 fd:00 3109 1028 8 0 8 0 0 0 libm-2.17.so
7f418181c000 ---p 00101000 fd:00 3109 2044 0 0 0 0 0 0 libm-2.17.so
7f4181a1b000 r--p 00100000 fd:00 3109 4 4 4 0 4 0 0 libm-2.17.so
7f4181a1c000 rw-p 00101000 fd:00 3109 4 4 4 0 4 0 0 libm-2.17.so
7f4181a1d000 r-xp 00000000 fd:00 3094 132 8 0 8 0 0 0 ld-2.17.so
7f4181bb0000 r--s 00000000 fd:00 274663 264 0 0 0 0 0 0 modules.dep
7f4181bf3000 r--s 00000000 00:13 20825 212 0 0 0 0 196 0 dbQN6MqZ (deleted)
7f4181c28000 rw-p 00000000 00:00 0 56 24 24 4 24 32 0
7f4181c36000 r--s 00000000 fd:00 132688 28 0 0 0 0 0 0 gconv-modules.cache
7f4181c3d000 rw-p 00000000 00:00 0 4 4 4 0 4 0 0
7f4181c3e000 r--p 00021000 fd:00 3094 4 4 4 0 4 0 0 ld-2.17.so
7f4181c3f000 rw-p 00022000 fd:00 3094 4 4 4 0 4 0 0 ld-2.17.so
7f4181c40000 rw-p 00000000 00:00 0 4 4 4 0 4 0 0
7ffd33f16000 rw-p 00000000 00:00 0 132 16 16 16 16 20 0 [stack]
7ffd33fce000 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]
====== ==== ==== ========== ========= ==== ======
188208 8296 7934 8140 7516 4788 0 KB
Here the third last column is showing the swap usage for this proc
Method 4
Now there is another way to find the swap memory usage which is among the best compared to above and reliable because it will give the swap usage for every library used by a process similar to above but in more detail.
For example to check the detail of "amsHelper" process
It will have blocks like below for every library file used by the process
Size: 132 kB
Rss: 16 kB
Pss: 16 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 16 kB
Referenced: 16 kB
Anonymous: 16 kB
AnonHugePages: 0 kB
Swap: 20 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd wr mr mw me gd ac
As you see it will gove you a long list so we must collect the required output and then calculate the entire value to get the overall usage report
4788
I hope the article was useful.