1
00:00:00,005 --> 00:00:01,005
- [Instructor] Let's talk more

2
00:00:01,005 --> 00:00:03,007
about the Linux kernel modules,

3
00:00:03,007 --> 00:00:07,007
dependencies, and the use count.

4
00:00:07,007 --> 00:00:09,006
So remember,

5
00:00:09,006 --> 00:00:15,002
the last two columns from lsmod show the use count,

6
00:00:15,002 --> 00:00:17,002
typically a small integer value

7
00:00:17,002 --> 00:00:21,000
like one or zero or maybe a little bit more.

8
00:00:21,000 --> 00:00:27,006
And then we have a list of modules separated by commas.

9
00:00:27,006 --> 00:00:30,009
Those are the used by modules.

10
00:00:30,009 --> 00:00:38,000
So the last one here, LLC, is used by STP and GARP.

11
00:00:38,000 --> 00:00:44,000
And the use count does not have to match those dependencies.

12
00:00:44,000 --> 00:00:45,005
A module can be in use

13
00:00:45,005 --> 00:00:48,006
even if another module doesn't need it.

14
00:00:48,006 --> 00:00:49,009
For example,

15
00:00:49,009 --> 00:00:58,008
if a process has opened up a file associated with a module,

16
00:00:58,008 --> 00:01:01,009
a driver module typically,

17
00:01:01,009 --> 00:01:04,005
then that would increment the use count.

18
00:01:04,005 --> 00:01:08,004
In general, the use count is used by the kernel

19
00:01:08,004 --> 00:01:14,001
to say a module's in use, and don't remove it.

20
00:01:14,001 --> 00:01:16,002
In the old days, the kernel

21
00:01:16,002 --> 00:01:20,006
would remove modules automatically that weren't in use.

22
00:01:20,006 --> 00:01:22,003
That turned out to be a bad idea (laughing)

23
00:01:22,003 --> 00:01:26,008
because removing modules is kind of risky.

24
00:01:26,008 --> 00:01:28,007
So the use counts may be not all that important

25
00:01:28,007 --> 00:01:32,007
'cause you don't want to be removing modules, typically.

26
00:01:32,007 --> 00:01:35,004
Dependency list is sometimes important

27
00:01:35,004 --> 00:01:37,008
because you can struggle to get a module loaded,

28
00:01:37,008 --> 00:01:39,006
because it needs modules

29
00:01:39,006 --> 00:01:43,003
and there's some sort of issue there.

30
00:01:43,003 --> 00:01:46,009
So the modules.dep file,

31
00:01:46,009 --> 00:01:49,002
and then there's a binary version of it

32
00:01:49,002 --> 00:01:50,006
that's actually faster to use,

33
00:01:50,006 --> 00:01:55,009
but modprobe uses the modules.dep files.

34
00:01:55,009 --> 00:01:58,001
When you modprobe a module,

35
00:01:58,001 --> 00:02:02,001
it's going to look up that module in the file,

36
00:02:02,001 --> 00:02:04,000
get the path to the module,

37
00:02:04,000 --> 00:02:09,001
and then also see what that module depends on

38
00:02:09,001 --> 00:02:11,001
and will load those modules.

39
00:02:11,001 --> 00:02:13,002
Incidentally, that's a comprehensive list,

40
00:02:13,002 --> 00:02:16,001
it doesn't have to like keep lookin' through the file

41
00:02:16,001 --> 00:02:18,001
to see if there's more.

42
00:02:18,001 --> 00:02:22,000
So here I grepped garp.ko,

43
00:02:22,000 --> 00:02:29,000
and I see the first line is the entry for the garp.ko.zst,

44
00:02:29,000 --> 00:02:36,000
and it depends on two other modules, STP and LLC.

45
00:02:36,000 --> 00:02:42,002
And then we see the line for the 8021q.

46
00:02:42,002 --> 00:02:44,008
And that depends on GARP,

47
00:02:44,008 --> 00:02:49,006
and that also depends on several other modules.

48
00:02:49,006 --> 00:02:52,003
So the GARP showed up in two cases,

49
00:02:52,003 --> 00:02:56,001
the module itself, and a module that depended on it.

50
00:02:56,001 --> 00:02:59,000
That's what modules.dep is all about.

