How to free swap without rebooting (to avoid hourly alert emails)?

I get alert emails whenever swap usage is at 100%. In my case, swap usage doesn't reduce later on (even though memory is free) so I get an alert email every hour.

How can I reduce swap usage without rebooting my Linux server?


Solution 1:

You can run swapoff -a as root to swap all memory back in. Don't forget to run swapon -a afterwards to make swap available again. Note that swapoff will fail if there is not enough physical memory available to swap everything back in.