By Default Ubuntu will move data in RAM onto the swap file/partition on the hard disk long before it runs out of memory. It will pick data that isn't accessed often but this can still be an annoying slow down on the system. To prevent the over use of SWAP space and speed things up all we need to do is change one setting... swappiness.
Swappiness can be set from 0 to 100. The default is 60 and the lower it is the more the computer will try to keep everything in RAM.
If you want to temporarily change the swappiness then run this command with desired swappiness level:
sudo sysctl vm.swappiness=10
Alternatively if you want the change to be permanent then edit this file:
sudo gedit /etc/sysctl.conf
Set swappiness to the desired level (in this case 1) by either modifying this line in the file "/etc/sysctl.conf" or if it doesn't exist, add it at the end.
vm.swappiness=1
Reboot the computer for the change to take effect.
Ubuntu Virtual Memory Swap Space RAM