How to Clear Linux Swap?

If you found that your linux system is using swap, and you want to clear out those swap usage.
Please try steps below:


  1. identify what is the current usage via "top" or "htop"
  2. try to turn off those applications that might cause high memory usage, like apache / mysql / php process.
  3. identify which partition was used for the SWAP usage
    1. # cat /etc/fstab
  4. now we can clear up the SWAP via 
    1. # swapoff /dev/sdax
  5. at the same time, try to monitor closely the SWAP space used in "top" or "htop", it should decrease slowly. And it shall be zero once the "swapoff" command finished.
  6. now, add back to SWAP partition via 
    1. # swapon /dev/sdax
  7. use back the "top" or "htop" to double check your SWAP usage.

And by now, your system should have cleared up those old SWAP usage. And it's time for you to do proper server planning, to add more memory of fine tune your configurations.


Cheers.

No comments: