Compiling Into the Kernel vs. Loadable Modules

Many parts of the FreeBSD kernel can be either:
(A) included in the kernel itself; or,
(B) built as a module loadable at runtime.

*How* to configure either choice is a well-documented topic. It is much more difficult to find guidance on which choice to make. When should a thing be compiled into the kernel? When should it be compiled as a module? Are there any best practices to follow?

For instance, should I:
- Compile everything the machine might ever need into the kernel, and don't build any modules?
- Compile the machine's everyday needs into the kernel, and build modules for occasional needs?
- Compile as minimal kernel as possible, and load everything else from modules?

Should I prefer to load modules in loader.conf, or via kldload?

To what extent will the system automatically load modules?

(My RTFM has discovered that the boot loader will load the acpi module automatically. The rc scripts will load pf, ipfw, and ipfilter automatically. A few of the geom commands will load their respective module if not loaded. As for other situations, it seems a manual process: the operator will need to invoke kldload prior to using the module's functionality.)

What's the direction FreeBSD is taking in the future with respect to this topic?
 
I usually keep my nic driver. most everything else is loaded unless specified that it has to be in the kernel. Never been much into giant monolithic kernels. Slimmer the better. But that's just me. I'm sure others have their thoughts about it.
 
SecretAsianMan said:
For instance, should I:
- Compile everything the machine might ever need into the kernel, and don't build any modules?
- Compile the machine's everyday needs into the kernel, and build modules for occasional needs?
- Compile as minimal kernel as possible, and load everything else from modules?
Highly subjective. I generally balance between option 1 and 2. Option 3 can be a real pain if a crucial module can't be loaded for whatever reason. Option 1 is nice for simplicity and in embedded environments.

SecretAsianMan said:
Should I prefer to load modules in loader.conf, or via kldload?
Depends if the module can be loaded after bootup and if you mind running kldload when you need it. :)

SecretAsianMan said:
To what extent will the system automatically load modules?
Some daemons and scripts auto load modules (eg. ppp), and the kernel auto loads to satisfy module dependencies, but FreeBSD doesn't have all the autoloading magic that linux has, for example.
 
aragon said:
I generally balance between option 1 and 2. Option 3 can be a real pain if a crucial module can't be loaded for whatever reason. Option 1 is nice for simplicity and in embedded environments.
That's sorta what I expected and hoped the answer would be.
 
What do you mean by "invoking kldload manually"? All modules I need are loaded in /boot/loader.conf (automatically, before starting the kernel).

That's why I generally prefer building GENERIC. There are a few rare cases where you need a custom kernel configuration (e.g. NFSv4, ALTQ, ...).

But as far as I understand, one should always prefer GENERIC and just load the modules on start. I also think, this is what the most people do. And besides that, GENERIC kernel is supported, custom kernels are not, if you run into very general trouble (of course, specific driver problems are always being solved by their developers).
 
There's no good reason why you would stick to GENERIC. It's full of stuff you're never gonna need, like ISA-bus nics, lots of scsi and raid controllers, etc, etc. Generic has support for 30 different PCI nics built in.

I'd say strip it down to the bare minimum and load modules for your specific needs.
 
jalla said:
It's full of stuff you're never gonna need, like ISA-bus nics, lots of scsi and raid controllers, etc, etc. Generic has support for 30 different PCI nics built in.
True. But the GENERIC kernel file is only 10MB big and the entire system barely uses ~60MB of memory on a fresh startup.
So the question is: what would you gain from removing the extra drivers? A few hundred KB? 1 or 2 MB at best? How about speed? The kernel is read from disk and loaded within a single second, or at most 2. Most modern machines (e.g. PIII and up) are so fast you cannot even see the "loading text section", "loading data section", etc. messages.
 
You compile your own kernel because :
1) You can and it's a rite of passage.
2) It's more secure.
3) Faster boot and better memory management. (more obvious with older hardware)

If you run GENERIC only and are not new to the UNIX world you need to reevaluate your administration ethic.

No one runs GENERIC on a production machine.
 
While I appreciate the last several responses, the question of whether or not to compile a custom kernel has nothing to do with this thread topic.

I'm using ALTQ, so a custom kernel is required.
 
Back
Top