Next: The Kernel Symbol Table
Up: Compiling and Loading
Previous: Compiling Modules
Contents
Loading and Unloading Modules
- After the module is built, the next step is loading it into the kernel. The ``insmod'' program loads the module code and data into the kernel, which, in turn, performs a function similar to that of , in that it links any unresolved symbol in the module to the symbol table of the kernel. Unlike the linker, however, the kernel doesn't modify the module's disk file, but rather an in-memory copy.
- How the kernel supports insmod: it relies on a system call defined in kernel/module.c. The function
allocates kernel memory to hold a module (this memory is allocated with vmalloc); it then copies the module text into that memory region, resolves kernel references in the module via the kernel symbol table, and calls the module's initialization function to get everything going.
- If you actually look in the kernel source, you'll find that the names of the system calls are prefixed with . This is true for all system calls and no other functions; it's useful to keep this in mind when grepping for the system calls in the sources.
- The ``modprobe'' utility is worth a quick mention. modprobe, like insmod, loads a module into the kernel. It differs in that it will look at the module to be loaded to see whether it references any symbols that are not currently defined in the kernel. If any such references are found, modprobe looks for other modules in the current module search path that define the relevant symbols. When modprobe finds those modules (which are needed by the module being loaded), it loads them into the kernel as well. If you use insmod in this situation instead, the command fails with an "unresolved symbols" message left in the system logfile.
- Modules may be removed from the kernel with the ``rmmod'' utility. Note that module removal fails if the kernel believes that the module is still in use (e.g., a program still has an open file for a device exported by the modules), or if the kernel has been configured to disallow module removal. It is possible to configure the kernel to allow "forced" removal of modules, even when they appear to be busy.
- The ``lsmod'' program produces a list of the modules currently loaded in the kernel. Some other information, such as any other modules making use of a specific module, is also provided. lsmod works by reading the /proc/modules virtual file. Information on currently loaded modules can also be found in the sysfs virtual filesystem under /sys/module.
Next: The Kernel Symbol Table
Up: Compiling and Loading
Previous: Compiling Modules
Contents
Cem Ozdogan
2007-05-16