To change or not to change swappiness – that is the question! But what is swappiness, and what role does it play on your Linux system? Well, for this read, we have put together a detailed guide on how and when you should consider changing swappiness on your MX Linux system.
So without further ado, let’s get started:
What is swappiness?
If you have installed your Linux system yourself, you should have run across the term – “swap space” during the partitioning phase. It is a dedicated part of your hard disk space used to substitute for the physical memory, a.k.a. RAM.
If and when the computer runs short of RAM, it will push certain processes into the swap space to ensure your system keeps working smoothly. As such, swap is also known as virtual memory.
The Linux kernel is programmed to automatically move certain inactive processes away from the RAM and into the swap space. This helps to free up the RAM – which is faster – for more memory-hungry processes and applications.
The tendency of how much or how often processes are moved to the swap space is called swappiness, and it is represented by a value between 0 – 100, where “100” means aggressively moving processes from the RAM and into the swap space.
By default, most Linux distros ship with a swappiness value of 60. However, with MX Linux, you get a swappiness value of 15 out of the box. So this brings the question – should I change the swappiness value on my MX Linux system? What changes can I expect with a higher or lower swappiness value? And how to change swappiness in MX Linux?
Well, we have answered all your questions in the following segments. That being said, here we covered a fundamental idea of swappiness. If you want a more technical overview of swappiness, you can look at this article – Swappiness in Linux: Everything you need to know.
Why should you change the swappiness value on your MX Linux system?
As we just discussed, the swappiness feature is involved with moving processes away from the RAM and into the swap space, which is a part of your HDD or SSD. As we all know, RAM is a much faster form of memory than HDD and SSD. As such, processes that run on RAM are faster and snappier compared to those running on HDD and SSD.
Now, if your MX Linux system has minimal RAM allocation – say less than 2GB, then having a high swappiness value makes sense. This will move your inactive processes into the swap space, freeing up your available RAM for your active processes and apps. As a result, you will get better performance from your system.
On the flip side, let’s say your MX Linux system has plenty of RAM, and you barely consume over 60-80% of your total available RAM. In that case, moving your apps to the swap space will result in decreased system performance since your HDD or SSD is much slower compared to your RAM. And so, for high RAM configuration systems, it isn’t recommended to set a high swappiness value.
What swappiness value to pick for your MX Linux system?
As a rule of thumb, Linux systems with less than 4GB of RAM are recommended to have a swappiness value of 60. At the same time, systems with over 16GB of RAM can get away with a swappiness value of 10 or lower.
However, as we said earlier, the swappiness value will mostly depend on how much free RAM you have in your day-to-day usage. For example, even if you use a 4GB RAM configuration system but barely reach 60% memory consumption, you should consider using a swappiness value of 10.
As such, if your Linux system is suffering from performance lag related to memory issues, we recommend that you experiment with different swappiness values and see which one gives you the best results.
How to change swappiness on MX Linux?
Before we go ahead and change the swappiness value on MX Linux, let’s first learn how to check the parameter.
The swappiness value is stored inside a file named – “swappiness” located inside the /proc/sys/vm/ directory. To check the swappiness value on your system, you can use your file manager to navigate to this file and open it. Inside you will find a single number denoting the swappiness value on your system.
However, if you are comfortable with the terminal, you can type in this single command to see the swappiness value:
Alternatively, you can also use this command:
On our system, this is the output we get:
As you can see, by default, the swappiness value is set to 15, which is excellent for systems running on high RAM configurations. However, our test system has 2GB of RAM. As such, we want to increase the swappiness value to 60.
To do this, type in the following command:
sudo sysctl vm.swappiness=60
Note: You can change “60” to any value between “0” and “100,” and that will be set as the new swappiness value.
After running this command, check if the swappiness value has changed:
As you can see, the swappiness value on our system has immediately changed to 60 without needing a reboot. However, do note that after you reboot your system, the swappiness value will reset to its default configuration – which in our case is “15.”
To make the changed swappiness value persistent even after performing a system reboot, you need to make changes directly to the /etc/sysctl.conf file.
To do this, first, open the file using the following command in the terminal:
sudo nano /etc/sysctl.conf
Note: We used nano, but you can use any other terminal text editor you like.
Inside the file, locate the vm.swappiness parameter and change its value to what you want. However, if you cannot find this parameter, add a new line “vm.swappiness=60” at the bottom of the file, as shown in the image below.
Once done, save your changes and exit the editor. You will now need to perform a system reboot to see the changes take place. After your system restarts, check the vm.swappiness parameter, showing the changed value.
And that’s it! You now know how to check and change and the swappiness value on your MX Linux system.
Changing the swappiness value on MX Linux is simple and can be done with a couple of commands. However, to get the best system performance, we recommend you experiment with different swappiness values and see which one works best for you.
As such, you should first make changes using the “sudo sysctl vm.swappiness=x” command. Then, once you find a value that works for you, make it persistent by adding it to the sysctl.conf file.
And that brings us to the end of our detailed guide on how to change swappiness on MX Linux. We hope you found this read useful and that it helped you clear all your confusion regarding swappiness on MX Linux.
Also, if you are new to Linux and just starting, we recommend checking out our Learn Linux series of articles which contains many more useful guides and articles such as this one.
“Once done, save your changes and exit the editor”
How do you save your changes?
There’s no save button etc… I’m a newb. Forgive me.
I used geany to edit the the sysctl.conf file.
I still don’t now how to save from terminal though. doh