Linux Swap Usage: Find Processes Using the Most Swap

Quick Linux Tip #87:

Question: My server is swapping. Which processes are the culprits?

Try: for pid in $(ls /proc/ | grep -E '^[0-9]+$'); do awk -v pid=$pid '/VmSwap/ {print pid, $2, $3}' /proc/$pid/status 2>/dev/null; done | sort -k2 -rn | head -10

Info: /proc/PID/status tracks per-process VmSwap usage. Iterating through numeric PIDs extracts and ranks memory-heavy processes pushed into swap space.

Examples:

  • $ sudo smem -tk -s swap  # Display total proportional swap consumption per process
  • $ grep VmSwap /proc/*/status | sort -k2 -rn | head  # Simple multi-proc status search
  • $ swapon --show  # List active swap devices, types, and total usage

Note: Persistent heavy swapping indicates memory exhaustion or leaks. Install smem for accurate proportional swap accounting, or tune swap behavior via sysctl vm.swappiness=10.




LinuxTeck.com
linuxteck:~$ for pid in $(ls /proc/ | grep -E '^[0-9]+$'); do awk -v pid=$pid '/VmSwap/ {print pid, $2, $3}' /proc/$pid/status 2>/dev/null; done | sort -k2 -rn | head -10
3456 234567 kB
2134 123456 kB
5678 89012 kB
1234 45678 kB
4567 23456 kB
6789 12345 kB
7890 8901 kB
8901 4567 kB

linuxteck:~$ ps -p 3456 -o pid,user,comm,rss,vsz
    PID USER     COMMAND       RSS       VSZ
   3456 mysql    mysqld        1234567   4567890
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #86: Linux File Attributes: Find and Remove Immutable Flags NEXT ARTICLE Quick Linux Tip #88: Chrony Time Synchronization: Fix Linux Clock Drift
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.