Ubuntu 9.06: Load used swap space back into RAM

13Jul 2009

Ubuntu 9.06: Load used swap space back into RAM

by Craig Mayhew on Mon 13th Jul 2009 under Linux/Ubuntu
When I have too many applications open or one of them eats all the memory I end up with a big chunk of my swap space used. The problem is that once I've closed a few programs or killed the offending program my computer still uses the swap space! I've read that the swap space will slowly be loaded back into RAM but only when it is next accessed. This results in sluggish system performance when the applications next read the memory in the swap space. To solve this problem you can empty the swap space and load it all back into RAM with one simple command. Please make sure you have enough RAM installed to load the memory in swap back into RAM...

This switches off swap memory and forces the system to load it back into RAM:

sudo swapoff -a


This switches swap back on incase you run out of RAM in the future:

sudo swapon -a


So now I can run those two commands, have the computer busy for 10-15 seconds and then know that it won't slow down again due to needing to access the swap (Unless it runs out of RAM again).

Linux/Ubuntu   Ubuntu 9.04   Virtual Memory   Swap Space   RAM  


© 2005-2024 Craig Mayhew