The Unexpected Disk Usage
By default, Ubuntu creates a swap file (or uses a swap partition) during installation. This swap space acts as an overflow area: when your physical RAM is full, the kernel moves inactive pages of memory to the swap file on disk. While essential on systems with limited RAM, a swap file on a modern machine with 16 GB or 32 GB of memory is rarely touched during normal usage. Yet Ubuntu keeps the swap file active at all times, consuming disk space (typically 2 GB or more), and the kernel’s default “swappiness” value (60) causes it to start swapping long before RAM is actually exhausted. This premature swapping slows down the system noticeably, particularly on machines with traditional hard drives rather than SSDs.
Disabling or Reducing Swap Usage
To stop Ubuntu from automatically using the swap file (or to reduce its aggressiveness), you can either disable swap entirely or lower the kernel’s swappiness parameter.
Open a terminal (Ctrl + Alt + T). To immediately disable swap, run sudo swapoff -a. This deactivates all swap partitions and swap files. To make this change permanent (so swap stays off after a reboot), edit the filesystem table: sudo nano /etc/fstab. Find the line that references your swap file or swap partition (it typically contains the word “swap”). Comment it out by adding a # at the beginning of the line. Press Ctrl + O to save and Ctrl + X to exit. If you prefer to keep swap available as a safety net but want the kernel to avoid using it unless absolutely necessary, lower the swappiness value instead. Run sudo sysctl vm.swappiness=10 to set it immediately. To make this persistent across reboots, run echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf. A swappiness value of 10 means the kernel will only swap when RAM usage is critically high, effectively keeping your system running from physical memory under normal workloads.