We were discussing clearing out swap today so I came up with this quick one-liner to clear out swap:

# free -m | grep -i swap; sudo swapoff -a && sudo swapon -a; free -m | grep -i swap

Swap:        5887         49       5838

Swap:         5887          0       5887

One caveat though, you may want to verify that there is enough memory available to free up swap. Likely the items in swap are old and you will not need it, but no sense having your server run out of memory unnecessarily.

Leave a Reply