Home » Questions » Computers [ Ask a new question ]

Releasing swap space

Releasing swap space

At times the kernel seems to be intent on keeping e.g. firefox in swap, even though there is enough physical memory available and I'm using firefox:

Asked by: Guest | Views: 213
Total answers/comments: 2
Guest [Entry]

"You could do a swapoff -- will need root privileges,
but, I guess that is not a problem for you."
Guest [Entry]

"Remember that the stuff in swap was put there at a busier time than now.

You might well find that the data is also in RAM - having been loaded back for use but not wiped from swap. The kernel does this to save time in the next busy period - if the data is already copied there it can just release the RAM it is using instead of having to do disk writes first. So unless you know the machine is not going to need to swap again in the near future, forcing the freeing of swap space may achieve nothing except to slow things down a little more next time swapping is needed.

This is managed on a delete-on-write basis, so if the copy in RAM is updated the blocks in swap will be released.

If the swap space is needed for something else, which it won't be at the moment as you have plenty free, it will of course be released for that use.

You can't see how much data is in this state (of being both in disk-based pages in swap areas, and in RAM) in the output from free. You can see it via the /proc special filesystem though. Look at the output of cat /proc/meminfo for the SwapCached count.

Another two reasons for there to be swap in use when there is apparently spare memory are

when under heavy I/O load the kernel has decided that pages that haven't been used for ages is better swapped out so it can use the RAM for cache/buffers, though looking at your free output that is probably not the case here as you have a chunk of truly unallocated RAM as well as that used by IO cache/buffers.
the pages were swapped out for some reason earlier, and just hasn't been needed again since - perhaps it is memory in use by a process that has been inactive for some time. In this case releasing the swap (so loading the pages back into RAM) may improve the response time of that process next time it is needed to do something other than sleep, but if it has been inactive for some time already it might not be needed at any time in the near future anyway."