Modular Kernel: Difference between revisions

From OSDev Wiki
Jump to navigation Jump to search
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:Kernel designs}}
{{Template:Kernel designs}}


(削除) ==What is a Modular Kernel== (削除ここまで)
A modular kernel is an attempt to merge the good points of kernel-level drivers and third-party drivers. In a modular kernel, some (追記) parts (追記ここまで)of the system core will be located in independent files called ''modules'' that can be added to the system at run time. Depending on the content of those modules, the goal can vary such as:
A modular kernel is an attempt to merge the good points of kernel-level drivers and third-party drivers. In a modular kernel, some (削除) part (削除ここまで)of the system core will be located in independent files called ''modules'' that can be added to the system at run time. Depending on the content of those modules, the goal can vary such as:
* only loading drivers if a device is actually found
* only loading drivers if a device is actually found
* only load a filesystem if it gets actually requested
* only load a filesystem if it gets actually requested
Line 13: Line 11:
==What are some advantages and disadvantages for a Modular Kernel?==
==What are some advantages and disadvantages for a Modular Kernel?==
===Advantages===
===Advantages===
* The (削除) most obvious is that the (削除ここまで)kernel doesn't have to load everything at boot time; it can be expanded as needed. This can decrease boot time, as some drivers won't be loaded unless the hardware they run is used (NOTE: This boot time decrease can be negligible depending on what drivers are modules, how they're loaded, etc.)
* The kernel doesn't have to load everything at boot time; it can be expanded as needed. This can decrease boot time, as some drivers won't be loaded unless the hardware they run is used (NOTE: This boot time decrease can be negligible depending on what drivers are modules, how they're loaded, etc.)
* The core kernel isn't as big
* The core kernel isn't as big
* If you need a new module, you don't have to recompile.
* If you need a new module, you don't have to recompile.
Line 19: Line 17:
===Disadvantages===
===Disadvantages===
* It may lose stability. If there is a module that does something bad, the kernel can crash, as modules should have full permissions.
* It may lose stability. If there is a module that does something bad, the kernel can crash, as modules should have full permissions.
* ...and therefore security is compromised. A module can do anything, so one could easily write an evil module to crash things. (Some OSs only allow modules to be loaded by the root user.)
* ...and therefore security is compromised. A module can do anything, so one could easily write an evil module to crash things. (Some OSs(追記) , like [https://en.wikipedia.org/wiki/Linux Linux], (追記ここまで)only allow modules to be loaded by the root user.)
* Coding can be more difficult, as the module cannot reference kernel procedures without kernel symbols.
* Coding can be more difficult, as the module cannot reference kernel procedures without kernel symbols.


Line 25: Line 23:


There are several components that can be identified in virtually every modular kernel:
There are several components that can be identified in virtually every modular kernel:
;(削除) the (削除ここまで)core
;(追記) The (追記ここまで)core
: (削除) this (削除ここまで)is the collection of features in the kernel that are absolutely mandatory regardless of whether you have modules or not.
: (追記) This (追記ここまで)is the collection of features in the kernel that are absolutely mandatory regardless of whether you have modules or not.
;(削除) the (削除ここまで)modules loader
;(追記) The (追記ここまで)modules loader
: (削除) this (削除ここまで)is a part of the system that will be responsible of preparing a module file so that it can be used as if it was a part of the core itself.
: (追記) This (追記ここまで)is a part of the system that will be responsible of preparing a module file so that it can be used as if it was a part of the core itself.
;(削除) the (削除ここまで)kernel symbols table
;(追記) The (追記ここまで)kernel symbols table
: This contains additional information about the core and loaded modules that the module loader needs in order to ''link'' a new module to the existing kernel.
: This contains additional information about the core and loaded modules that the module loader needs in order to ''link'' a new module to the existing kernel.
;(削除) the (削除ここまで)dependencies tracking
;(追記) The (追記ここまで)dependencies tracking
: As soon as you want to ''unload'' some module, you'll have to know whether you can do it or not. Especially, if a module ''X'' has requested symbols from module ''Z'', trying to unload ''Z'' while ''X'' is present in the system is likely to cause havoc.
: As soon as you want to ''unload'' some module, you'll have to know whether you can do it or not. Especially, if a module ''X'' has requested symbols from module ''Z'', trying to unload ''Z'' while ''X'' is present in the system is likely to cause havoc.
;(削除) modules (削除ここまで)
;(追記) Modules (追記ここまで)
: Every part of the system you might want (or don't want) to have.
: Every part of the system you might want (or don't want) to have.
(削除) (削除ここまで)


== How can such a system boot in first place ?==
== How can such a system boot in first place ?==


Modularization must be done within certain limits if you still want your system (削除) to be able (削除ここまで)to boot. Pushing ''all'' (削除) the filesystems (削除ここまで)and device drivers (including boot device driver) into (削除) module (削除ここまで)will (削除) probably (削除ここまで)make the boot time (削除) a hard time (削除ここまで). (削除) Following (削除ここまで)solutions can however be used:
Modularization must be done within certain limits if you still want your system to boot. Pushing ''all'' (追記) filesystem (追記ここまで)and device drivers (including (追記) the (追記ここまで)boot device driver) into (追記) modules (追記ここまで)will (追記) likely (追記ここまで)make the boot time (追記) more complicated (追記ここまで). (追記) The following (追記ここまで)solutions can(追記) , (追記ここまで)however(追記) , (追記ここまで)be used:
* The kernel is provided with an extremely simple [[File Systems|filesystem]] (e.g. SCO's [[BFS]]) driver and that filesystem contains modules to access the rest of system storage (e.g. module for ATA, SCSI, EXT2FS, [[ReiserFS]], FAT, NTFS ...).
* The kernel is provided with an extremely simple [[File Systems|filesystem]] (e.g. SCO's [[BFS]]) driver and that filesystem contains modules to access the rest of system storage (e.g. module for ATA, SCSI, EXT2FS, [[ReiserFS]], FAT, NTFS ...).
* The kernel comes with a built-in native file system driver (削除) and (削除ここまで)other storage modules (削除) as well as (削除ここまで)primary configuration files should be stored using that native filesystem. This was the approach followed by Linux, and (削除) as soon as (削除ここまで)some people decided to (削除) have (削除ここまで)[[ReiserFS|reiser]] everywhere, ext2-fs only kernels (削除) start (削除ここまで)having trouble on some machines.
* The kernel comes with a built-in native file system driver (追記) with (追記ここまで)other storage modules(追記) , and (追記ここまで)primary configuration files should be stored using that native filesystem. This was the approach followed by Linux, and (追記) when (追記ここまで)some people decided to (追記) use (追記ここまで)[[ReiserFS|reiser]] everywhere, ext2-fs only kernels (追記) started (追記ここまで)having trouble on some machines.
* The bootloader knows it should not only load the ''kernel'' but also a collection of pre-configured modules so (削除) that (削除ここまで)the kernel only needs to check (削除) those (削除ここまで)pre-loaded modules (削除) and initialize them (削除ここまで)to access other modules and primary configuration files. This (削除) basically (削除ここまで)means that your bootloader (削除) is somehow (削除ここまで)an OS of its own such as [[GRUB]]
* The bootloader knows it should not only load the ''kernel'' but also a collection of pre-configured modules so the kernel only needs to check (追記) and initialize (追記ここまで)pre-loaded modules to access other modules and primary configuration files. This means that your bootloader (追記) acts as (追記ここまで)an OS of its own(追記) , (追記ここまで)such as [[GRUB]](追記) . (追記ここまで)


(削除) Anyway (削除ここまで), ramdisk drivers and dedicated boot partitions/reserved sectors will be your friends.
(追記) In this case (追記ここまで), ramdisk drivers and dedicated boot partitions/reserved sectors will be your friends.


==See Also==
==See Also==
===Threads===
===(追記) Forum (追記ここまで)Threads===
*[[Topic:10031|Design of a basic module loader]]
*[[Topic:10031|Design of a basic module loader]]
*[[Topic:9921|Calling a function knowing its name]]
*[[Topic:9921|Calling a function knowing its name]]

Latest revision as of 17:18, 7 May 2019

Kernel Designs
Models
Other Concepts

A modular kernel is an attempt to merge the good points of kernel-level drivers and third-party drivers. In a modular kernel, some parts of the system core will be located in independent files called modules that can be added to the system at run time. Depending on the content of those modules, the goal can vary such as:

  • only loading drivers if a device is actually found
  • only load a filesystem if it gets actually requested
  • only load the code for a specific (scheduling/security/whatever) policy when it should be evaluated
  • etc.

The basic goal remains however the same: keep what is loaded at boot-time minimal while still allowing the kernel to perform more complex functions. The basics of modular kernel are very close to what we find in implementation of plugins in applications or dynamic libraries in general.

What are some advantages and disadvantages for a Modular Kernel?

Advantages

  • The kernel doesn't have to load everything at boot time; it can be expanded as needed. This can decrease boot time, as some drivers won't be loaded unless the hardware they run is used (NOTE: This boot time decrease can be negligible depending on what drivers are modules, how they're loaded, etc.)
  • The core kernel isn't as big
  • If you need a new module, you don't have to recompile.

Disadvantages

  • It may lose stability. If there is a module that does something bad, the kernel can crash, as modules should have full permissions.
  • ...and therefore security is compromised. A module can do anything, so one could easily write an evil module to crash things. (Some OSs, like Linux, only allow modules to be loaded by the root user.)
  • Coding can be more difficult, as the module cannot reference kernel procedures without kernel symbols.

What does a Modular Kernel look like ?

There are several components that can be identified in virtually every modular kernel:

The core
This is the collection of features in the kernel that are absolutely mandatory regardless of whether you have modules or not.
The modules loader
This is a part of the system that will be responsible of preparing a module file so that it can be used as if it was a part of the core itself.
The kernel symbols table
This contains additional information about the core and loaded modules that the module loader needs in order to link a new module to the existing kernel.
The dependencies tracking
As soon as you want to unload some module, you'll have to know whether you can do it or not. Especially, if a module X has requested symbols from module Z, trying to unload Z while X is present in the system is likely to cause havoc.
Modules
Every part of the system you might want (or don't want) to have.

How can such a system boot in first place ?

Modularization must be done within certain limits if you still want your system to boot. Pushing all filesystem and device drivers (including the boot device driver) into modules will likely make the boot time more complicated. The following solutions can, however, be used:

  • The kernel is provided with an extremely simple filesystem (e.g. SCO's BFS) driver and that filesystem contains modules to access the rest of system storage (e.g. module for ATA, SCSI, EXT2FS, ReiserFS, FAT, NTFS ...).
  • The kernel comes with a built-in native file system driver with other storage modules, and primary configuration files should be stored using that native filesystem. This was the approach followed by Linux, and when some people decided to use reiser everywhere, ext2-fs only kernels started having trouble on some machines.
  • The bootloader knows it should not only load the kernel but also a collection of pre-configured modules so the kernel only needs to check and initialize pre-loaded modules to access other modules and primary configuration files. This means that your bootloader acts as an OS of its own, such as GRUB.

In this case, ramdisk drivers and dedicated boot partitions/reserved sectors will be your friends.

See Also

Forum Threads

Retrieved from "https://wiki.osdev.org/index.php?title=Modular_Kernel&oldid=23607"