Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What command can be used to force release everything in swap partition back to memory ?

Presume that I have enough memory.

share|improve this question
up vote 10 down vote accepted

From this Ask Ubuntu question:

You can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.


$ free -tm
Swap:         6439        196       6243
$ sudo swapoff -a
$ sudo swapon -a
$ free -tm
Swap:         6439          0       6439

As noted in a comment, if you don't have enough memory, swapoff will result in "out of memory" errors and on the kernel killing processes to recover RAM.

share|improve this answer
Explaining this further, if you don't have enough available RAM swapoff will result in out of memory errors and the kernel will start killing processes to recover some. Use this with caution. – bahamat Aug 14 '12 at 9:15
Better hope so; linux behaves pretty hilariously when you run out of memory with no active swap at all... – Shadur Aug 14 '12 at 9:19


sudo bash -c 'swapoff -a && swapon -a'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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