What command can be used to force release everything in swap partition back to memory ?
Presume that I have enough memory.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
From this Ask Ubuntu question:
You can also clear your swap by running
swapoff -aand then
swapon -aas root instead of rebooting to achieve the same effect.
$ free -tm ... Swap: 6439 196 6243 ... $ sudo swapoff -a $ sudo swapon -a $ free -tm ... Swap: 6439 0 6439 ...
As noted in a comment, if you don't have enough memory,
swapoff will result in "out of memory" errors and on the kernel killing processes to recover RAM.
As noted, simply deactivating all swap will cause the kernel to start killing things if it doesn't have enough free memory. If you wish to avoid that, create a second set of swap first. Then:
swapon /second/swap/device && swapoff /first/swap/device swapon /first/swap/device && swapoff /second/swap/device
This will still swap in everything, but if there's not enough space it'll get shifted to the second swap device instead of randomly killing things. Then just shift it all back.
sudo bash -c 'swapoff -a && swapon -a'