Frequently Asked Question
What KVM is using all my swap on proxmox?
Last Updated 4 days ago
Swap usage can be an issue, especially when you come in to find it at 98% and everything is chugging. There's no easy way in proxmox to see who's using all that swap and whilst tools like smem can show you, the information is vague.
The following script, which we call showswap.sh and place in ~ shows you exactly who's using your swap so you can restart it.
#!/bin/bash
printf "%-10s %-8s %s\n" "SWAP" "PID" "COMMAND"
for pid in $(pgrep -x kvm); do
swap=$(grep VmSwap /proc/$pid/status 2>/dev/null | awk '{print $2}')
if [ ! -z "$swap" ] && [ "$swap" -gt 0 ]; then
cmd=$(ps -p $pid -o args= | cut -c1-80)
printf "%-10s %-8s %s\n" "$((swap/1024)) MB" "$pid" "$cmd"
fi
done | sort -hr
Once you've put this in showswap.sh, don't forget to make it executable with
chmod +x showswap.sh
and then execute it with
./showswap.sh