Skip to content

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:

free -h

Look at the output:

              total        used        free      shared  buff/cache   available
Mem:           62Gi        38Gi       18Gi        512Mi       6Gi        23Gi
Swap:           8Gi         3Gi        5Gi

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:

swapoff -a && swapon -a

This can take a few minutes depending on how much data is in swap and disk speed. Monitor progress:

watch -n2 free -h

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:

cat /proc/sys/vm/swappiness

Apply immediately (takes effect without reboot):

sysctl vm.swappiness=10

Make it permanent:

echo "vm.swappiness=10" >> /etc/sysctl.conf
sysctl -p

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