Back to Engineering Blog
Infrastructure & Reliability 3 min read

Swap at 99.9% With Half the RAM Free: Add Headroom, Then Ask Why

A hypervisor reported swap almost completely full while RAM was only half used. We checked the swap layout read-only first, then added a 16 GiB swapfile with correct permissions and a persistent fstab entry. The deeper question, why it was swapping at all, stays open.

Jason NevillBy , Houston, TX
#Proxmox#Linux#Memory#Swap

Key Architectural Takeaways

  • Diagnose the existing swap layout read-only before changing it.
  • A root-only swapfile with a persistent fstab entry is a low-risk way to add headroom on a host with spare disk.
  • More swap treats the symptom; why the host was swapping with half its RAM free still needs an answer.

The alert

A hypervisor reported swap usage at 99.92% (7.99 of 8.00 GiB) while RAM use sat around 50%. Nothing had failed yet, but a host with no swap left has no room to absorb a memory spike, and the kernel's next option is the OOM killer.

Diagnose before changing

The first task was read-only. We looked at how swap was provided (zram, zswap, an LVM or ZFS swap volume or a swapfile), the storage layout and the free space, and proposed a plan for human review instead of acting at once.

The change

On this host the 8 GiB was a conventional swap volume and the root filesystem had spare room, so the simplest safe option was a swapfile:

  • A 16 GiB /swapfile created on the root logical volume and activated.
  • Permissions 0600, owned by root, because a world-readable swap file can leak memory contents.
  • A persistent entry in /etc/fstab (/swapfile none swap sw,pri=10 0 0), so it survives a reboot.

Result

Total swap went from 8.00 GiB to 23.99 GiB. Used swap stayed at 8.00 GiB, now about 33% of the total and down from 99.92%, leaving 16 GiB of headroom. The root filesystem kept more than 41 GiB free.

What this does not answer

Swap pressure with half the RAM free is odd. It can mean the kernel is aggressively swapping out cold pages, a few guests have large idle footprints, or a memory limit is set lower than the guest wants. More swap relieves the alarm without explaining it. We recorded the follow-up as a separate question: look at swappiness, per-guest memory and what is actually resident in swap.

Takeaway

Adding headroom is the right immediate step when a host is about to hit a wall. Write down the root-cause question in the same breath, or it will resurface as the next alert.

Some of what's described here is a design that hasn't been fully tested yet; those parts say so in the text.

Follow the build on LinkedIn or by RSS.

All Articles

Follow the build

Questions about the build, or spotted something we got wrong? Find us on LinkedIn and GitHub.