Find Which Process Uses Swap on Raspberry Pi¶
Use /proc/PID/status to find which processes have private memory in swap on your Raspberry Pi. Then use vmstat during the slowdown to see whether pages are moving now. A process can hold pages in swap while the Pi is running normally.
1. Check which swap devices are active¶
Run this on the Pi host.
USED shows the space occupied on each swap device or file. Raspberry Pi OS Trixie can use /dev/zram0, a compressed block device in RAM. If several devices appear, the process check below gives a process's swap usage across devices. Use the ZRAM setup guide to identify what manages each device.
2. List processes by VmSwap¶
This Bash snippet reads one status file per visible process and prints the ten largest nonzero values. The first column is in KiB.
Pick a PID from the output and inspect it again. Substitute the PID from your Pi.
VmRSS is the process's resident memory. VmSwap covers swapped private anonymous memory. Shared-memory pages and the processes visible from your account or container can affect how the list compares with the system total. A process that exits during the scan can disappear from the results. Linux process status fields
3. Check whether swapping is happening now¶
Run the sample while the problem occurs. Use -y to omit the first report based on activity since boot.
Read si for swap-in and so for swap-out in each interval. If both stay at zero while the listed swap usage stays steady, the sample shows pages occupying swap with no current transfer. If either stays active during the slowdown, repeat the process list and compare it with the workload running at that time. A large VmSwap value identifies where pages came from. A different process may have triggered memory pressure. vmstat field reference
4. Read the RAM cost when using ZRAM¶
Compare DATA, the uncompressed data size, with TOTAL, the RAM allocated for the compressed device including allocator overhead. DISKSIZE is the device's configured capacity. Compression depends on the contents of the pages. Linux ZRAM statistics
On a Pi 4B with Raspberry Pi OS Trixie, a test process moved a 4 MiB buffer containing a repeating pattern to ZRAM. The process appeared in the list with VmSwap: 4096 kB, swapon showed 4 MiB used, and zramctl reported 48 KiB of allocated RAM under TOTAL. The first one-second sample showed so at 4096 and the next four reported zero. Closing the test mapping released the swap slots.
If the samples show ongoing stalls or a service was killed, continue with the memory pressure and OOM checks before changing swap settings.