<preamble>
This lecture was first given at the MCA day at VJTI, and then
repeated along with a demonstration of the proc filesystem at the
Linux workshop at VJTI
Note: This has to be read along with the following files:
/usr/src/linux/Documentation/
kmod.txt
modules.txt
man modprobe
man insmod
man lsmod
man kerneld
man ksyms
I'd also suggest reading Linux Device Drivers, 2nd Edition
http://www.xml.com/ldd/chapter/book/index.html
</preamble>
Monolithic kernels and Microkernels
- Linux was based on Minix
- Minix has a microkernel, but it doesn't do it very well
- Linux has a monolithic kernel
- Linux was written because Linus wanted to learn how his 386 works
What's the difference?
Monolithic
- the whole kernel is a single a.out file
- the whole kernel is loaded into memory
- all communication within the kernel is through in process data structures
Microkernel
- most of the OS is outside the kernel
- services communicate via message passing
- the kernel implements this message passing
- the kernel also implements interrupt handling, low-level process
management, and possibly IO.
Linux is obsolete - AST
OS Researchers have generally settled on the fact that microkernels are
better.
This was decided back in the mid to late eighties.
So, is linux obsolete?
Modules
- No one really knows who came up with the idea
- It was first implemented in the 0.99 kernel series
- insmod, rmmod, modprobe and kerneld
How does it work?
- All modules are not linked into the kernel at build time
- Slots that have been marked as modules are left empty
- These slots are actually linked to an internal function called
request_module()
What happens if a module is needed?
The kerneld way:
- The kernel notices that a feature is requested that is not resident in
the kernel.
- The kernel sends a message to kerneld, with a symbolic description of
the requested feature.
- The kerneld daemon asks e.g. modprobe to load a module that fits this
symbolic description.
- modprobe looks into its internal "alias" translation table to see if
there is a match. This table can be reconfigured and expanded by
having "alias" lines in "/etc/modules.conf".
- insmod is then asked to insert the module(s) that modprobe has decided
that the kernel needs. Every module will be configured according to
the "options" lines in "/etc/modules.conf".
- modprobe exits and kerneld tells the kernel that the request succeeded
(or failed...)
- The kernel uses the freshly installed feature just as if it had been
configured into the kernel as a "resident" part.
modprobe, insmod, kerneld? What are these things?
- kerneld is just another daemon.
- runs in the background, communicates with the kernel through Sys V IPC
- loads modules when required, unloads them after (usually) 1 minute of
no use
- insmod links a loadable module into a running kernel
- it must resolve symbols from the kernel's exported symbol table
- modprobe is a wrapper for insmod
- it checks modules for dependencies listed in modules.dep
- it checks its alias file
- it loads all matching modules, and their support modules
But that's not the way it's done anymore
- As of 2.1.90-pre1, kerneld has been replaced by kmod
- kmod is a kernel thread, not a user space daemon
- kmod doesn't do everything that kerneld did
B-b-but why?
- in the end, modprobe is called, so why have an extra user space
process?
- kerneld used Sys V IPC to communicate with kernel
- doesn't use unix domain sockets for logging
- code size of ipc/msg.c decreased by 40%
So what does kmod do?
- has a replacement for request_module()
- runs as a separate kernel thread called kmod
- when a module is requested, kmod wakes up and execve()s modprobe
And what must I do?
- kmod needs to know where it can find modprobe
- echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
- or use sysctl
- of course, you could put this in your startup scripts and forget about
it
- you also need to manually unload unused modules... but that's what
cron is for
So....
- the modular kernel doesn't use up as much memory as traditional
monolithic kernels
- kernel modules can be updated without recompiling the kernel
- your kernel can be really small
- Linux is not obsolte, on the contrary, we can all look forward to
version 3.0
--
Scully: I'm seeing a whole new side of you, Mulder.
MulderEddie: Is that a good thing?
Scully: I like it.
"The X-Files: Small Potatoes"
Visit my webpage at
http://www.ncst.ernet.in/~philip/
Read my writings at
http://www.ncst.ernet.in/~philip/writings/
MSN philiptellis Yahoo! philiptellis
AIM philiptellis ICQ 129711328