/proc/modules 只列出正确加载的内核模块吗?

huangapple go评论57阅读模式
英文:

Does /proc/modules only list kernel modules that are correctly loaded?

问题

The red hat documentation regarding this file is vague. At first, it states that:

> This file displays a list of all modules loaded into the kernel

但后来在文档中,它说:

> 第三列列出了当前加载的模块实例数量。值为零表示未加载的模块。

所以我的问题是:

  1. 如果一个模块的第三个值为0,这是否意味着它现在在内核中已经不再加载了?如果是的话,为什么它们仍然都有内核地址?

  2. 如果 /proc/modules 只显示当前加载的内核模块,那么我如何找到在启动后会自动加载的所有内核模块的列表?

英文:

The red hat documentation regarding this file is vague. At first, it states that:

> This file displays a list of all modules loaded into the kernel

But then later in the doc, it says:

> The third column lists how many instances of the module are currently
> loaded. A value of zero represents an unloaded module.

So my questions are:

  1. If the third value for a module is 0, does this mean that it is no longer loaded in the kernel right now? If so, then why do all of them still have a kernel address?

  2. If /proc/modules only shows the currently loaded kernel modules, how can I find the list of all the kernel modules that will get loaded automatically after boot?

答案1

得分: 2

根据/kernel/module/procfs.c,这第三个值不是实例的数量,而是模块的引用计数(module_refcount)。

如果一个模块的引用计数大于0,那么它不能安全卸载(其他模块期望它仍然存在),但如果引用计数为0,该模块可以卸载,但目前仍然加载着。

不知道为什么这个文档记错了。

一个名为systemd-modules-load.service的systemd服务在启动时加载模块。这里有一些关于它如何工作以及在哪里查找的文档。
然而,对于没有systemd的系统,有一个不同的服务,我相当确定您有其他加载模块的方式。

英文:

1.
According to /kernel/module/procfs.c this third value is not the number of instances, but the reference count of the module (module_refcount).

If a module has a reference count > 0 than it can't be unload safely (other modules expect it to be there), but if the reference count is 0 the module can be unloaded, but it's still loaded as of now.

Don't know why this documentation got it wrong.

2.
A systemd service called systemd-modules-load.service loads modules at boot time. here is some documentation that shows how it works and where to look.
However, there is a different service for systems withoud systemd and I'm pretty sure you have some other ways of loading a modules.

huangapple
  • 本文由 发表于 2023年7月6日 15:54:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76626652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定