From what I read, the purpose of depmod is to track dependencies for each kernel module for when it gets loaded. Why can't this be simply determined automatically when the kernel module is loaded, similar to dynamically loading a userspace shared library?
The depmod (Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a “Makefile”-like dependency file named modules.
Using modules can save memory, because they are loaded only when the system is actually using them. All parts of the base kernel stay loaded, in real storage, not just virtual storage. Modules are much faster to maintain and debug.
A kernel module is a program which can loaded into or unloaded from the kernel upon demand, without necessarily recompiling it (the kernel) or rebooting the system, and is intended to enhance the functionality of the kernel.
depmod does more than just compute direct dependencies - it also builds a mapping between hardware identifiers and the modules that handle them. This is used to find the correct module to load for a detected piece of hardware.
As for why it doesn't do demand loading like userspace does, part of this is because the kernel linker is not allowed to access the filesystem, by design. The philosophy in the kernel is the layout of the filesystem is completely up to userspace, and so there's no guarantee that foo.ko
will be found in /lib/modules/3.0.1/drivers/somesubsys/foo.ko
. As such, the kernel relies on userspace utilities (like depmod and modprobe) to pass it the raw data for its modules, in the order it needs to load them; if userspace fails in this job, it simply returns an error, and lets userspace deal with the mess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With