1
00:00:00,000 --> 00:00:10,600
In this video, you learn how to tune kernel parameters.

2
00:00:10,600 --> 00:00:12,980
So how does kernel tuning in general work?

3
00:00:12,980 --> 00:00:18,940
Well, the Linux kernel has many settings that can be tuned through the PROC SYS interface.

4
00:00:18,940 --> 00:00:23,760
For more details about that interface, you can find manproc, because there's a lot of

5
00:00:23,760 --> 00:00:29,420
parameters that can be changed and it's impossible to know about all of them.

6
00:00:29,420 --> 00:00:33,820
Now if you want to change a setting, the new setting can be echoed into the PROC VAL and

7
00:00:33,820 --> 00:00:36,220
it will be applied immediately.

8
00:00:36,220 --> 00:00:40,560
And that is the recommended methodology if you want to know if you're on the right track

9
00:00:40,560 --> 00:00:43,779
by changing a specific parameter.

10
00:00:43,779 --> 00:00:47,700
For instance, in this class, we are going to tweak the SWAPPINESS parameter.

11
00:00:47,700 --> 00:00:52,060
The SWAPPINESS parameter is a parameter that tells the kernel what to do in case of memory

12
00:00:52,060 --> 00:00:54,299
shortage.

13
00:00:54,299 --> 00:00:56,980
It has a value between 0 and 200.

14
00:00:56,980 --> 00:01:04,059
A value closer to 0 means that it is going to drop inactive cache to make more memory

15
00:01:04,059 --> 00:01:05,059
available.

16
00:01:05,059 --> 00:01:10,500
A value closer to 200 means that the kernel is going to move inactive anonymous memory

17
00:01:10,500 --> 00:01:12,239
to swap.

18
00:01:12,239 --> 00:01:15,540
So echo 30 would be quite conservative.

19
00:01:15,540 --> 00:01:20,099
Now once you have written your parameter and you verified that it works, you are going

20
00:01:20,099 --> 00:01:23,260
to use SYSCTL.

21
00:01:23,260 --> 00:01:24,260
So what is SYSCTL?

22
00:01:24,260 --> 00:01:29,980
Well, SYSCTL is the interface that allows you to manage PROC SYS parameters in an easy

23
00:01:29,980 --> 00:01:30,980
way.

24
00:01:30,980 --> 00:01:35,860
It's a good idea to start with SYSCTL-A, which will show all settings which are available

25
00:01:35,860 --> 00:01:38,820
for tuning on your system.

26
00:01:38,820 --> 00:01:42,540
Notice that the settings that you will see are different according to what is installed

27
00:01:42,540 --> 00:01:47,199
on your system hardware-wise as well as software-wise.

28
00:01:47,199 --> 00:01:53,220
The parameters that you are going to see in the output of SYSCTL-A are filenames.

29
00:01:53,220 --> 00:01:58,180
Filenames relative to slash PROC slash SYS, where the slash as a separator between directories

30
00:01:58,180 --> 00:02:02,360
and files has been replaced with a dot.

31
00:02:02,360 --> 00:02:11,440
So slash PROC slash SYS slash VM slash swappiness in SYSCTL-A shows as vm.swappiness.

32
00:02:11,440 --> 00:02:16,639
If you want to make settings persistent, you can write them to etc.sysctl.conf or to a drop-in

33
00:02:16,639 --> 00:02:21,880
file that is created in etc.sysctl.d.

34
00:02:21,880 --> 00:02:26,080
So the value would be, for instance, vm.swappiness is 60.

35
00:02:26,080 --> 00:02:31,839
Write it to a file, any name.conf will work, and it will be picked up.

36
00:02:31,839 --> 00:02:37,320
You can activate the changes by rebooting or also by re-reading the configuration file

37
00:02:37,320 --> 00:02:39,679
using sysctl-p.

38
00:02:39,679 --> 00:02:41,399
Let me show you.

39
00:02:41,399 --> 00:02:48,960
So first, let me show you a cat to slash PROC slash SYS slash VM slash swappiness, currently

40
00:02:48,960 --> 00:02:49,960
set to 60.

41
00:02:50,039 --> 00:02:58,720
All right, I'm going to echo 150, greater than PROC SYS VM swappiness.

42
00:02:58,720 --> 00:03:03,000
This is the only way how you can change files in the PROC SYS file system, because this

43
00:03:03,000 --> 00:03:08,679
is a pseudo file system, it's not a real file system, so different rules apply.

44
00:03:08,679 --> 00:03:12,759
When I use my cat, I see the new value, and this is where I can do my testing.

45
00:03:12,759 --> 00:03:18,039
For instance, I can use 3 minus m to see if this changes the situation, where we still

46
00:03:18,119 --> 00:03:22,399
see that not a lot of swap is used at all.

47
00:03:22,399 --> 00:03:28,800
That kind of makes sense, because we have still two gigs in available memory, but maybe

48
00:03:28,800 --> 00:03:34,960
if we start Firefox as a background process, maybe that is working, and yeah, that's not

49
00:03:34,960 --> 00:03:38,320
working at all, because I'm trying to start it as root.

50
00:03:38,320 --> 00:03:45,600
Let me try to start it from the graphical user interface, and then I do my 3 minus m,

51
00:03:45,600 --> 00:03:46,600
and what is it showing?

52
00:03:47,160 --> 00:03:49,800
Well, it's showing that still no swap is being used.

53
00:03:49,800 --> 00:03:54,839
It's going off of the available memory, and it doesn't change anything.

54
00:03:54,839 --> 00:03:57,720
That's the thing with these settings in PROC SYS.

55
00:03:57,720 --> 00:04:01,600
You might think that you're on the wrong track, but there's one way to find out only, and

56
00:04:01,600 --> 00:04:03,320
that is by testing.

57
00:04:03,320 --> 00:04:07,479
Now I'm going to ignore my tests, and I'm going to assume that this is the setting that

58
00:04:07,479 --> 00:04:09,160
I want to have anyway.

59
00:04:09,160 --> 00:04:10,160
Now what would I do?

60
00:04:10,399 --> 00:04:20,160
Well, I would create etc sysctl.d slash swappiness.conf.

61
00:04:20,160 --> 00:04:24,600
It's a good convention to use the name of the parameter followed by .conf, but that's

62
00:04:24,600 --> 00:04:25,600
just a recommendation.

63
00:04:25,600 --> 00:04:28,839
Feel free to do it differently if you want to.

64
00:04:28,839 --> 00:04:37,480
So here I'm putting vm.swappiness is 150.

65
00:04:37,799 --> 00:04:41,160
Next, well, do I need to use sysctl minus b?

66
00:04:41,160 --> 00:04:45,040
Honestly, not really, because I manually set it already.

67
00:04:45,040 --> 00:04:47,559
What is nice is sysctl minus a.

68
00:04:47,559 --> 00:04:52,839
There you can see an overview of all these different tunables, and there is a lot of

69
00:04:52,839 --> 00:04:53,839
them.

70
00:04:53,839 --> 00:04:57,040
On this system, 1,080 in total.

71
00:04:57,040 --> 00:05:03,079
You'll always be around 1,000 parameters, so there's a lot going on there, so much that

72
00:05:03,079 --> 00:05:09,320
knowing how to optimize your system by using these parameters is really an art by itself,

73
00:05:09,320 --> 00:05:12,880
an art that we are not going to further explore in this video.

