Find Which Processes are Using Swap

I was doing some testing on my Virtuozzo linux VPS and wanted to find what was using the swap. The short version is that processes that have not been used in a long time will be moved into swap to free up RAM.

I found the following page with a one-liner to show the running processes and the amount of swap they are using (including processes with 0 kB of swap). https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/ I modified the one-liner to only show processes using swap.

for file in $(grep -El "VmSwap:\s+[1-9][[:digit:]]* kB" /proc/*/status) ; do awk '/Name:|VmSwap:/{printf $2 " " $3}END{ print "" }' $file; done | sort -k2nr

php-fpm 488792 kB
php-fpm 485172 kB
php-fpm 475640 kB
php-fpm 469504 kB
php-fpm 469100 kB
php-fpm 462044 kB
php-fpm 439604 kB
php-fpm 430868 kB
php-fpm 410124 kB
php-fpm 389892 kB
php-fpm 381132 kB
php-fpm 380136 kB
php-fpm 379988 kB
php-fpm 379216 kB
php-fpm 316296 kB
mysqld 225884 kB
php-fpm 92096 kB
php-fpm 91920 kB
php-fpm 84464 kB
php-fpm 83408 kB
php-fpm 82244 kB
httpd 15128 kB
httpd 13460 kB
httpd 12896 kB
tuned 12812 kB
httpd 12776 kB
polkitd 7204 kB
php-fpm 5272 kB
httpd 4892 kB
httpd 4616 kB
snmpd 2748 kB
VGAuthService 1624 kB
NetworkManager 1372 kB
rsyslogd 1160 kB
vmtoolsd 1076 kB
master 1028 kB
qmgr 1020 kB
sshd 928 kB
systemd-udevd 580 kB
crond 560 kB
lvmetad 408 kB
systemd 396 kB
auditd 340 kB
dbus-daemon 304 kB
chronyd 260 kB
systemd-journal 176 kB
systemd-logind 164 kB
irqbalance 164 kB
agetty 128 kB

Restarting php-fpm freed up most of the swap.

Comments

Popular posts from this blog

Linux: Permanent CIFS/SMB mount

Plesk - Decrypt FTP Passwords

IPTables: Clear all rules