Today’s article is just going to be a quick and easy article, where we learn how to clear swap. I figured I’d do this article while swap was still fresh in my memory so that I’d not forget to write it down the road. If you use swap and want to learn how to clear swap, read on!
Again, this article is only useful for those that use a swap. There are different opinions about using swap and this article is for those who do. I just wrote an article about how to monitor swap, so we might as well learn to clear it.
What do I mean by clearing swap? I mean emptying it. I mean removing all the data held in swap, allowing for data to be written to swap again. It’s not something I worry about, but I know folks have asked about it in the past. I might just as well cover it, though it really won’t take much time.
This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press
With your terminal now open, you can clear swap with the following command, by turning swap off:
sudo swapoff -a
You then turn swap back on with:
sudo swapon -a
Tada! You’re all done. If you want, you can do it all with just a one-liner:
sudo swapoff -a && sudo swapon -a
That’s really all there is to it. It’s not terribly complicated and it’s something you might as well know if you’re going to use swap and are concerned with monitoring and clearing it.
There you have it. I told you that it’d be short and easy. You now know how to clear swap, should you actually want to do so. You might as well know how. It’s bound to come in handy for someone.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.