Blog

[FREEBSD] How to clean up swap from old rubbish

You want to clear your swap – all articles are saying – just do swapoff/swapon but you getting error:
swapoff: /dev/xbd25: Cannot allocate memory
What to do? Easy, make some file with size of your swap, add it as swap, turn off old one, turn on old one and remove the file! Easy:
[shell]
dd if=/dev/zero of=/usr/jails/swap0 bs=1m count=10240
#10gb of swap
mdconfig -a -t vnode -f /usr/jails/swap0 -u 0
mdconfig -l -v md0 vnode 10G /usr/jails/swap0
swapon /dev/md0
swapinfo
Device 1K-blocks Used Avail Capacity
/dev/xbd25 15728640 7773260 7955380 49%
/dev/md0 10485760 0 10485760 0%
Total 26214400 7773260 18441140 30%
swapoff /dev/xbd25
swapon /dev/xbd2
swapoff /dev/md0
[/shell]

Comments are closed.

Marek Knappe