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:13,000
So how does kernel tuning in general work?

3
00:00:13,000 --> 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,440
parameters that can be changed and it's impossible to know about all of them.

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

7
00:00:33,799 --> 00:00:36,240
it will be applied immediately.

8
00:00:36,240 --> 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,799
by changing a specific parameter.

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

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

12
00:00:52,040 --> 00:00:54,279
shortage.

13
00:00:54,279 --> 00:00:57,000
It has a value between 0 and 200.

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

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

16
00:01:05,080 --> 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,559
So echo 30 would be quite conservative.

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

20
00:01:20,120 --> 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,419
Well, SYSCTL is the interface that allows you to manage PROC SYSCTL parameters in an

23
00:01:29,419 --> 00:01:30,419
easy way.

24
00:01:30,419 --> 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,180
on your system hardware-wise as well as software-wise.

28
00:01:47,180 --> 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,160
Filenames relative to slashproc slash sys, where the slash as a separator between directories

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

31
00:02:02,339 --> 00:02:11,419
So slashproc slash sys slash vm slash swappiness in SYSCTL-A shows as vm.swappiness.

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

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

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

35
00:02:26,100 --> 00:02:27,100
Write it to a file.

36
00:02:27,100 --> 00:02:31,839
Any name.conf will work, and it will be picked up.

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

38
00:02:37,300 --> 00:02:39,660
using sysctl-p.

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

40
00:02:41,399 --> 00:02:48,979
So first, let me show you cat to slashproc slash sys slash vm slash swappiness, currently

41
00:02:48,979 --> 00:02:49,979
set to 60.

42
00:02:49,979 --> 00:02:50,979
All right.

43
00:02:51,100 --> 00:02:58,699
So I'm going to echo 150, greater than proc sys vm swappiness.

44
00:02:58,699 --> 00:03:02,979
This is the only way how you can change files in the proc sys file system, because this

45
00:03:02,979 --> 00:03:04,779
is a pseudo file system.

46
00:03:04,779 --> 00:03:08,660
It's not a real file system, so different rules apply.

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

48
00:03:12,699 --> 00:03:17,979
For instance, I can use 3 minus m to see if this changes the situation, where we still

49
00:03:17,979 --> 00:03:22,380
see that not a lot of swap is used at all.

50
00:03:22,380 --> 00:03:28,259
That kind of makes sense, because we have still two gigs in available memory.

51
00:03:28,259 --> 00:03:34,740
But maybe if we start Firefox as a background process, maybe that is working, and yeah,

52
00:03:34,740 --> 00:03:38,259
that's not working at all, because I'm trying to start it as root.

53
00:03:38,259 --> 00:03:42,699
Let me try to start it from the graphical user interface.

54
00:03:42,699 --> 00:03:46,740
And then I do my 3 minus m, and what is it showing?

55
00:03:46,779 --> 00:03:49,779
Well, it's showing that still no swap is being used.

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

57
00:03:54,820 --> 00:03:57,699
That's the thing with these settings in proc sys.

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

59
00:04:01,580 --> 00:04:03,339
that is by testing.

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

61
00:04:07,460 --> 00:04:09,139
I want to have anyway.

62
00:04:09,139 --> 00:04:10,139
Then what would I do?

63
00:04:10,380 --> 00:04:20,100
Well, I would create etc sysctl.d slash swappiness.conf.

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

65
00:04:24,540 --> 00:04:25,899
just a recommendation.

66
00:04:25,899 --> 00:04:28,779
Feel free to do it differently if you want to.

67
00:04:28,779 --> 00:04:37,420
So here I'm putting vm.swappiness is 150.

68
00:04:37,420 --> 00:04:41,260
And next, well, do I need to use sysctl minus b?

69
00:04:41,260 --> 00:04:45,059
Honestly, not really, because I manually set it already.

70
00:04:45,059 --> 00:04:47,540
What is nice is sysctl minus a.

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

72
00:04:52,859 --> 00:04:53,859
them.

73
00:04:53,859 --> 00:04:57,019
On this system, 1,080 in total.

74
00:04:57,019 --> 00:05:02,059
You'll always be around 1,000 parameters, so there's a lot going on there.

75
00:05:02,059 --> 00:05:07,500
Thank you so much that knowing how to optimize your system by using these parameters is really

76
00:05:07,500 --> 00:05:12,899
an art by itself, an art that we are not going to further explore in this video.

