In this video, you learn how to tune kernel parameters.
So how does kernel tuning in general work?
Well, the Linux kernel has many settings that can be tuned through the PROC SYS interface.
For more details about that interface, you can find manproc, because there's a lot of
parameters that can be changed and it's impossible to know about all of them.
Now if you want to change a setting, the new setting can be echoed into the PROC VAL and
it will be applied immediately.
And that is the recommended methodology if you want to know if you're on the right track
by changing a specific parameter.
For instance, in this class, we are going to tweak the SWAPPINESS parameter.
The SWAPPINESS parameter is a parameter that tells the kernel what to do in case of memory
shortage.
It has a value between 0 and 200.
A value closer to 0 means that it is going to drop inactive cache to make more memory
available.
A value closer to 200 means that the kernel is going to move inactive anonymous memory
to swap.
So echo 30 would be quite conservative.
Now once you have written your parameter and you verified that it works, you are going
to use SYSCTL.
So what is SYSCTL?
Well, SYSCTL is the interface that allows you to manage PROC SYS parameters in an easy
way.
It's a good idea to start with SYSCTL-A, which will show all settings which are available
for tuning on your system.
Notice that the settings that you will see are different according to what is installed
on your system hardware-wise as well as software-wise.
The parameters that you are going to see in the output of SYSCTL-A are filenames.
Filenames relative to slash PROC slash SYS, where the slash as a separator between directories
and files has been replaced with a dot.
So slash PROC slash SYS slash VM slash swappiness in SYSCTL-A shows as vm.swappiness.
If you want to make settings persistent, you can write them to etc.sysctl.conf or to a drop-in
file that is created in etc.sysctl.d.
So the value would be, for instance, vm.swappiness is 60.
Write it to a file, any name.conf will work, and it will be picked up.
You can activate the changes by rebooting or also by re-reading the configuration file
using sysctl-p.
Let me show you.
So first, let me show you a cat to slash PROC slash SYS slash VM slash swappiness, currently
set to 60.
All right, I'm going to echo 150, greater than PROC SYS VM swappiness.
This is the only way how you can change files in the PROC SYS file system, because this
is a pseudo file system, it's not a real file system, so different rules apply.
When I use my cat, I see the new value, and this is where I can do my testing.
For instance, I can use 3 minus m to see if this changes the situation, where we still
see that not a lot of swap is used at all.
That kind of makes sense, because we have still two gigs in available memory, but maybe
if we start Firefox as a background process, maybe that is working, and yeah, that's not
working at all, because I'm trying to start it as root.
Let me try to start it from the graphical user interface, and then I do my 3 minus m,
and what is it showing?
Well, it's showing that still no swap is being used.
It's going off of the available memory, and it doesn't change anything.
That's the thing with these settings in PROC SYS.
You might think that you're on the wrong track, but there's one way to find out only, and
that is by testing.
Now I'm going to ignore my tests, and I'm going to assume that this is the setting that
I want to have anyway.
Now what would I do?
Well, I would create etc sysctl.d slash swappiness.conf.
It's a good convention to use the name of the parameter followed by .conf, but that's
just a recommendation.
Feel free to do it differently if you want to.
So here I'm putting vm.swappiness is 150.
Next, well, do I need to use sysctl minus b?
Honestly, not really, because I manually set it already.
What is nice is sysctl minus a.
There you can see an overview of all these different tunables, and there is a lot of
them.
On this system, 1,080 in total.
You'll always be around 1,000 parameters, so there's a lot going on there, so much that
knowing how to optimize your system by using these parameters is really an art by itself,
an art that we are not going to further explore in this video.