Swappiness is a setting in the Linux kernel which controls how amenable to paging things in memory out to disk the kernel is (like using virtual memory in Windows), and in Ubuntu it comes with a default value of 60 – which for a box with lots of memory is too high in my humble opinion. The range of values goes from 0 (never use the swap file unless absolutely critical) to 100 (page stuff out to file whenever it feels like).
You can easily check your current swappiness value like this:
And you can change the swappiness of the system on the fly (but it’ll go back to the value in the sysctl.conf file after a reboot) like this:
sudo sysctl vm.swappiness=10
My laptop has 4GB of RAM, and even with a bunch free, Linux decides to swap stuff out to file quite often with a swappiness setting of 60, which can slow the box to a crawl. To fix this, and permanently insist that all physical RAM is used up before starting any paging at all,, simply change the setting to something like 10 like this:
gksudo gedit /etc/sysctl.conf
Then, when the file is open, either add the line vm.swappiness=10 to the bottom of the file, or if it already exists just modify the value, then reboot.
To find out more about the whole swappiness thing, try this article.