Clean Swap Linux

Posted on  by admin
  1. Clear Swap Linux
  2. Clean Swap Linux Software
  3. Clean Swap Linux Command

Swap is a virtual memory concept that allows your system to use a portion of your hard drive as the physical memory (RAM). Your system swaps the inactive pages in memory in RAM to this swap space on the hard disk. This way, your system has more free RAM available for other programs.

I have shown you to check RAM in Linux and I have also discussed how to check swap usage on Linux. In this quick tip, I’ll show you how to clear swap memory in Linux.

Like with most modern Linux distributions, on Ubuntu you can use two different forms of swap. The classic version has the form of a dedicated partition. It’s usually set up while installing your OS on your HDD for the first time and exists outside the Ubuntu OS, its files, and your data.

On most distributions of Linux, it is recommended that you set swap space when installing the operating system. The amount of swap space you can set for your Linux system may depend on the architecture and kernel version. How do I check Swap space usage in Linux? INFO Adding a swapfile after a clean installation without swap partition Post by erikdubois » Sun Jul 21, 2019 10:59 am Best decide what to do in the beginning inside Calamares - 3 choices regarding swap. Linux cleans up disk cache on demand. Inactive disk cache pages will be evicted when memory is needed. If you change the value of /proc/sys/vm/swappiness, you can alter the bias between reclaiming inactive file cache, and reclaiming inactive 'anonymous' (swap-backed) program memory. The default is already biased against swapping.

Clear swap in Linux


But first, why would you want to clear swap at all? There could be various reasons. Some time your system will use a lot of swap even when plenty of RAM is available.

This may or may not be associated with swappiness of your system. Sometimes it happens that the RAM doesn’t swap back the pages from swap space to RAM. In such cases, you’ll have to manually clear the swap.


Before clearing the swap, check that you have enough free RAM available to take all the pages from swap. In other words, you should have more free RAM available than the current swap in use.

You can see the state of RAM and swap using the free command in Linux:


Once you are sure that the size of free RAM is bigger than the swap memory in use, you can clear the swap memory by turning it off and on again.

Clean Swap LinuxClean

Pun aside, that’s the way to do it. Disable all the swap using this command:

Clear Swap Linux

Now turn the swap back on:

Clean Swap Linux Software

That’s it. This simple exercise will clear the swap in your Linux system. I hope you find this little tip helpful. Any questions or suggestions are always welcome.

Become a Member for FREE
Become a member to get the regular Linux newsletter (2-4 times a month) and access member-only contents.

Clean Swap Linux Command

Join the conversation.