Proxmox — Clear Swap Without Reboot
After starting several VMs or containers, the PVE host's swap fills up. You can clear it without rebooting — but only if there is enough free RAM to absorb what is currently swapped out.
Before You Start: Check If It Is Safe
swapoff forces the kernel to move everything from swap back into RAM. If free RAM is less than current swap usage, the kernel runs out of memory and the host will crash or OOM-kill processes.
Check both values first:
Look at the output:
The Swap used must be less than Mem available. In the example above: 3 GB used in swap, 23 GB RAM available — safe to proceed.
Do not proceed if available RAM < swap used
Running swapoff without enough free RAM will cause the host to OOM. If you are in this situation, free up RAM first by stopping VMs or containers, or accept that a reboot is the safer option.
Clear Swap
Disable all swap, then re-enable it. The kernel moves swapped pages back to RAM and the swap partition is cleared:
This can take a few minutes depending on how much data is in swap and disk speed. Monitor progress:
Swap used should drop toward 0.
Reduce Swappiness to Prevent Refilling
The default vm.swappiness value is 60, which means the kernel starts swapping relatively aggressively. For a Proxmox host where VMs manage their own memory, a lower value keeps swap mostly empty under normal load.
Check current value:
Apply immediately (takes effect without reboot):
Make it permanent:
A value of 10 means the kernel strongly prefers keeping processes in RAM and only swaps under real memory pressure. 0 would disable swap-out entirely for anonymous pages, but is not recommended on a host — swap still acts as a safety net when a VM unexpectedly consumes more memory than allocated.
Common Issues
| Symptom | Cause | Fix |
|---|---|---|
Host becomes unresponsive after swapoff |
Not enough free RAM | Stop VMs/CTs first to free memory, then retry |
| Swap refills quickly after clearing | Swappiness too high | Set vm.swappiness=10 permanently |
swapoff: not permitted |
Not running as root | Use sudo or run as root |
Swap stays at same level after swapon -a |
swapoff did not finish |
Wait for the watch output to show 0, then run swapon -a |