Take the 2-minute tour ×
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.

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
add comment

1 Answer

up vote 6 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.

Thus:

$ 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
2  
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
add comment

Your Answer

 
discard

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.