ProjectsCase study 03

The swap problem that wasn't what it looked like

Swap on my main host had been filling up for as long as the lab existed. Every review ended at an alarming number with no cause. This time I wrote the history down, measured each container separately, and found two different things hiding behind one number.

Result
5.7 GB → 17 MB
host swap in use
Safeguard
A weekly check that alerts only on a real overrun
When
September to November 2026
Stack
Proxmox VE, Docker, Linux control groups, systemd timers

The problem

The host showed 5.7 GB of swap in use. It also had 7 GB of memory free and a CPU that was 99% idle after 37 days of uptime. Those facts don't fit a machine that is short of memory.

The other problem was the missing history. The issue had been looked at several times and never recorded, so every review started from zero. The first thing I did was write an entry describing what had already been tried.

Finding 1: most of it was residue

Swap in use is a running total, and it doesn't shrink by itself. Pages pushed out during a busy moment stay there until something needs them again. What matters is whether the system is swapping now, so the first check became the swap-out rate. It was zero. Most of the 5.7 GB was cold pages left over from past events.

Finding 2: the real overruns were silent

Some containers had memory limits that were too small for their busiest moments. By default, Docker lets a container that hits its limit spill into swap instead of stopping it. Nothing failed and nothing alerted. The container just got slower and left more residue behind.

Each container keeps its own counters for limit hits and swap written, so I read those for every container, not only the one under suspicion. Then I ran a controlled test on one of them: the same kind of large file transfer, before and after raising its limit.

One container, one large transfer1 GiB limit2 GiB limit
Its own memory, peak532 MB1,111 MB
Swap in use, peak213 MB0
Swap written to diskAbout 1.05 GB0

Given room, the container used twice the memory and wrote nothing to swap. The old limit had been squeezing it the whole time.

What I changed

  • Resized the limits on the containers that were hitting them, one at a time, each with a backup of the file and a check afterwards.
  • Added a daily restart timer for one service whose embedded browser leaks memory.
  • Wrote a weekly swap check that alerts only when a container's own limit hits have grown and at least 256 MB of swap was written, or when anything was killed for running out of memory. An alert now means a real overrun, and residue is ignored.

What I chose not to do

  • Clearing swap by turning it off and on. It would have forced 5.7 GB back into memory at once and removed the evidence without fixing a cause.
  • Disabling swap. Swap is a useful cushion. The fault was the limits.
A correction I kept in the record

My first write-up called one long-held theory, that large file transfers drove the swap, disproved. A controlled test three days later showed transfers do push that one container into swap, just not the multi-gigabyte total. I corrected the entry and left the original wording visible.

What I would do next

  • Sweep every container's counters when any alert fires. A later check that followed one alert missed a second container overrunning at the same moment.