不幸的是,Linux没有很好的文档记录,阅读源代码和建立直觉仍然是了解它如何工作的主要途径.
__meminit
在linux/init.h中定义为
#define __meminit __section(".meminit.text") __cold notrace \
__latent_entropy
The comment at the top of this file briefly explains how the __init
macro is used to mark functions that are used only during initialization and that later can be discarded.
__meminit
is a specialized version of __init
, it marks a function that is used during memory initialization.
As the comment /* Used for MEMORY_HOTPLUG */
before the definition of __meminit
implies, it is used with memory hotplug.
Presumably, the kernel won't free the memory initialization functions if memory hotplug is enabled since these can be needed at any time (e.g. when a new DIMM is inserted). But it will still free other initialization functions.
从普通代码中调用标记为__XXXinit
的函数通常是不安全的(它可能不再存在),但如果您正在编写处理内存热插拔的代码,那么您知道内核不会释放__meminit
个函数,因此调用它们是安全的(在此上下文中).
所有这__XXXinit
个宏的工作原理相似,它们将函数/变量放在具有特定名称的部分中,以便内核稍后可以释放它.
__meminit
扩展为:
您可以看到,所有这些属性对于初始化函数来说都是有意义的