We have a linux machine, in which the swap partition gets filled to the limit from time to time. There's still enough of RAM free, so there should be no risk of running out of memory.
The usual course of action in case of a full swap is to execute a swapoff -a && swapon -a to completely clear the swap.

My Questions:

  1. Is the full swap partition a problem which needs attention in the first place, or is it something "normal", which can just be ignored.
  2. Is turning the swap off and on again a good thing to do, or does it make the situation worse, because the kernel now gets busy clearing the swap space?
  3. What would be a better (or the best) way to react?
  • 4
    Why do you want to "react"? – Matteo Aug 4 '15 at 6:14

Clearing the swap is not necessary nor useful. Read linuxatemyram.

The kernel has a quite efficient page cache. So RAM is used for useful data (e.g. recently accessed file segment chunks, or heap memory), and less useful data got swapped to the swap zone.

Perhaps your swap zone might be too small. You could also swap to some file. See this.


In my experience a full swap partition has only been happening in cases where the memory usage has been high. Under such circumstances disabling swap could be a problem because there might not be enough memory to load everything back from swap.

If you attempt to disable swap with insufficient free memory, the system may become unresponsive or start killing processes to free up memory.

If memory usage has been high and later dropped again, the swap utilization might be high, but I would be surprised to see it at 100% since whatever caused memory to be released would likely also have released at least a few pages of swap.

If you disable swap after memory usage has already dropped, you are likely not causing lots of problems by disabling swap. But I also don't think you are doing anything of benefit to your system performance.

Whenever I have seen a system with full swap, then I have been able to improve performance by adding more swap.


As the other answers say, it's not a good idea to clear out the swap manually. However, if you notice that both swap and memory are completely filled and other programs have trouble running because of that, something can be amiss.

In such a case, run htop and sort by memory usage by clicking on MEM%. This will allow you to find programs that use an extraordinarily high amount of memory. If you find something that seems to not fit there (a small utility for example), turn to google and try to find out if that program has a known memory leak. It's unlikely, but can happen.

In my case, I found out that the i3 notification manager dunst had a memory leak that was known and fixed but the fixed version was not in my distro's repositories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.