Add these lines to the end of /etc/sysctl.conf:
vm.swappiness=5
vm.min_free_kbytes=122880
vm.vfs_cache_pressure=500
Run these commands as root:
sudo sysctl -w vm.swappiness=5;
sudo sysctl -w vm.min_free_kbytes=122880
sudo sysctl -w vm.vfs_cache_pressure=500
Explanation:
vm.swappiness
- Reducing this value tells the virtual machine to avoid swapping to disk unless it is actually running low on memory.vm.min_free_kbytes
- Increasing this value makes sure files can be loaded from the disk without first having to swap other things out of memory.vm.vfs_cache_pressure
- Increasing this causes file-caches to be thrown away rather than swapped out to disk. Opening files will be a tiny amount slower, but switching between applications will be faster.