The Swappiness Factor
Ubuntu Linux uses a “swap” file or partition as virtual memory. When your system’s physical RAM (Random Access Memory) starts to fill up, the kernel automatically moves (or “swaps” out) older, less frequently accessed memory pages from the fast RAM to the slower hard drive space. The aggressiveness of this behavior is controlled by a value called “swappiness.” By default, Ubuntu’s swappiness is set to 60 (on a scale of 0 to 100), meaning the system will start aggressively moving data to the slow disk even when you still have 40% of your fast RAM free. This causes unnecessary disk thrashing and significantly slows down overall system responsiveness.
Reducing Automatic Swapping Behavior
To maximize the use of your fast physical memory and stop Ubuntu from automatically clearing active data to the slow swap space prematurely, you must lower the swappiness value.
To check your current swappiness, open a terminal (Ctrl+Alt+T) and run cat /proc/sys/vm/swappiness (it will likely return 60). To temporarily change this to prioritize RAM (making the system wait until RAM is 90% full before swapping), run sudo sysctl vm.swappiness=10. To make this change permanent so it survives a reboot, you must edit the system configuration file. Run sudo nano /etc/sysctl.conf. Scroll to the very bottom of the file and add the following line: vm.swappiness=10. Save the file (Ctrl+O, Enter) and exit nano (Ctrl+X). Your system will now utilize your physical RAM much more efficiently, resulting in a snappier desktop experience.