How to configure Ubuntu to prioritize the usage of swap memory over physical memory?

By default, Ubuntu uses a priority-based approach when it comes to memory management. It utilizes the swap space when the physical memory (RAM) is running low. However, if you want to prioritize the usage of swap memory over physical memory, you can modify the swappiness value.


Swappiness is a kernel parameter that determines how aggressively the system uses swap space. By increasing the swappiness value, you can encourage Ubuntu to use swap memory more frequently.


Here's how you can modify the swappiness value:


1. Open a terminal on your Ubuntu system.

2. Check the current swappiness value by running the following command:


   cat /proc/sys/vm/swappiness


   The default value is usually 60.

3. To temporarily set the swappiness value to a higher value (e.g., 100), use the following command:


   sudo sysctl vm.swappiness=100


   This change will take effect immediately and will persist until you reboot your system.

4. If you want to make the change persistent across reboots, you need to edit the `/etc/sysctl.conf` file. Open it with a text editor using the following command:


   sudo nano /etc/sysctl.conf


5. At the end of the file, add the following line to set the swappiness value:


   vm.swappiness=100


   You can replace "100" with the desired value according to your preference.

6. Save the file and exit the text editor.

7. To apply the changes, run the following command:


   sudo sysctl -p

With the increased swappiness value, Ubuntu will be more likely to use swap memory. However, keep in mind that using excessive swap can negatively impact performance, as accessing data from swap is slower than accessing data from RAM. It's generally recommended to have a balanced swappiness value based on your system's specific requirements.