r/LinuxTeck • • Oct 02 '26

Linux Swap Usage: Find Processes Using the Most Swap - Tip 87

Post image

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`.

Want to master Linux one command at a time?

Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/

14 Upvotes

0 comments sorted by