Swappiness is a Linux kernel parameter that controls the balance between swapping out idle processes and using available RAM memory. The default swappiness value in most Linux distributions is 60, which means the system starts swapping out processes when the available memory falls below 40%. However, this default value might not be suitable for all situations, and changing the swappiness value can improve system performance.
In this article, we will discuss how to change the swappiness value in Linux. We will cover different methods to change the swappiness value temporarily and permanently.
Temporary Change Swappiness Value
To change the swappiness value temporarily, you can use the sysctl command. This command allows you to modify the kernel parameters at runtime.
Here are the steps to change the swappiness value temporarily:
- Check the current swappiness value
Before changing the swappiness value, you can check the current value by using the following command:
cat /proc/sys/vm/swappiness
The output will be a number between 0 and 100, indicating the current swappiness value.
- Change the swappiness value
To change the swappiness value temporarily, you can use the following command:
sudo sysctl vm.swappiness=<value>
Replace <value> with the desired swappiness value. For example, if you want to set the swappiness value to 10, you can use the following command:
sudo sysctl vm.swappiness=10
This will set the swappiness value to 10, which means the system will start swapping out processes when the available memory falls below 90%.
- Verify the new swappiness value
You can verify the new swappiness value by using the cat command:
cat /proc/sys/vm/swappiness
The output should be the new swappiness value that you set.
Permanent Change Swappiness Value
To make the swappiness value permanent across reboots, you can modify the sysctl.conf file. This file is used to set kernel parameters at boot time.
Here are the steps to make the swappiness value permanent:
- Edit the sysctl.conf file
You can open the sysctl.conf file using a text editor. For example, you can use the nano editor:
sudo nano /etc/sysctl.conf
- Add the swappiness value
Add the following line at the end of the file:
vm.swappiness=<value>
Replace <value> with the desired swappiness value. For example, if you want to set the swappiness value to 10, you can add the following line:
vm.swappiness=10
After adding the swappiness value, save and close the file.
- Apply the changes
To apply the changes, run the following command:
sudo sysctl -p
This will load the new swappiness value from the sysctl.conf file.
- Verify the new swappiness value
You can verify the new swappiness value by using the cat command:
cat /proc/sys/vm/swappiness
The output should be the new swappiness value that you set.
Conclusion
Changing the swappiness value in Linux can improve system performance in certain situations. In this article, we discussed how to change the swappiness value temporarily and permanently. By following the steps outlined above, you can set the swappiness value to a value that best suits your needs.