Memory Optimizations
Unlike user-space code and data, kernel code and data reside permanently in main memory, so it is important to reduce memory waste in every way possible. Initialization code is a good candidate for memory optimization . Given their nature, most initialization routines are executed either just once or not at all, depending on the kernel configuration. For example:
The
module_initroutines are executed only once when the associated module is loaded. When the module is statically included in the kernel, the kernel can free themodule_initroutine right at boot time, after it runs.The
module_exitroutines are never executed when the associated modules are included statically in the kernel. In this case, therefore, there is no need to includemodule_exitroutines into the kernel image (i.e., the routines can be discarded at link time).
The first case is a runtime optimization, and the second one is a link-time optimization.
Code and data that are used only during the boot and are not needed thereafter are
placed in one of the memory sections shown in Figure 7-3. Once the kernel has completed the initialization phase, it can
discard that entire memory area. This is accomplished by the call to free_init_mem,[*] as shown in Figure 5-1 in
Chapter 5. Different macros are used to place
code into the different memory sections of Figure 7-3.
If you look at the example in the earlier section "New Model: Macro-Based Tagging," you can
see that the two input routines to module_init ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access