A report job barely makes progress, the CPU is idle and free shows 11 GB free. Yet over 1 GB sits in swap and pages are swapped in and out all the time. The machine has enough memory – but the job is not allowed to use it.
Symptom
journalctl -u berichtsjob --no-pager -o short-precise
Nov 30 23:17:07.055941 perf1 python3[76376]: Runde 10: 1563 Zugriffe/s
free -m
total used free shared buff/cache available
Mem: 11961 1051 10918 1 239 10909
Swap: 4095 1184 2911
1,563 accesses per second instead of about 400,000 in the test run – with 11 GB free memory.
Diagnosis
Measure pressure and ask the process how much of it sits in swap.
cat /proc/pressure/io some avg10=81.90 avg60=72.83 avg300=51.50 total=358481984 full avg10=81.58 avg60=72.70 avg300=51.40 total=355599221 grep VmSwap /proc/76376/status VmSwap: 935256 kB
Causes
memory.high = 600 MiBSoft limit smaller than the working set
The deployment set MemoryHigh=600M while the working set is 1.5 GB. The kernel keeps the limit by pushing the rest into swap.
cat /sys/fs/cgroup/system.slice/berichtsjob.service/memory.high 629145600 cat /sys/fs/cgroup/system.slice/berichtsjob.service/memory.events high 3612 max 0 oom 0 oom_kill 0
PSI io, not memorySwapping in counts as I/O waiting
PSI counts waiting for a page from swap as I/O pressure. In the steady state memory pressure is low – so looking at PSI memory alone is misleading.
no OOMhigh slows down, max kills
memory.high is a soft limit: there is no OOM kill, the job just gets extremely slow. memory.events counts 3,612 hits on high and none on max.
Fix
sudo systemctl set-property --runtime berichtsjob MemoryHigh=2G time sudo swapoff /swapfile real 0m56.554s sudo swapon /swapfile
Don't: Buy more RAM – there was plenty free. Or run swapoff on a system without enough free memory for everything in swap.
Linux system performance hands-on, day 7: memory pressure, swap, the OOM killer and leaks – and a job that may not use its memory.
Go to day 7 →
FAQ
Why does PSI memory show little pressure although everything is stuck in swap?
PSI measures memory pressure mainly during reclaim. Waiting for swapped-in pages counts as I/O pressure.
How fast does the job recover after raising the limit?
Without swapoff the kernel only brings pages back on access, which can take up to half an hour. With swapoff the job ran almost 300 times as fast after a minute in the course.