Problem:

我经常看到__meminit个decorator 在Linux源代码中放在函数前面.我想知道__meminit个装修工是什么意思.

例.在arch/x86/mm/init_64.c年中: static void __meminit remove_pagetable(unsigned long start, unsigned long end, bool direct, struct vmem_altmap *altmap)

Attempts:

我try 查看宏的定义,如下所示

/* Used for MEMORY_HOTPLUG */
#define __meminit        __section(.meminit.text) __cold notrace \
                          __latent_entropy

但还是不懂它的用法.

Follow-up Question:

Linux初学者在哪里可以找到这样的宏的描述?

推荐答案

不幸的是,Linux没有很好的文档记录,阅读源代码和建立直觉仍然是了解它如何工作的主要途径.

__meminitlinux/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扩展为:

您可以看到,所有这些属性对于初始化函数来说都是有意义的

Linux相关问答推荐

X86_64程序集中的分段故障:系统调用问题

Docker 不保留 chown 用户设置

Google Cloud Ops Agent Mongo 集成错误 - AuthenticationFailed:SCRAM 身份验证失败,storedKey 不匹配

使用 sed 或 awk 在 linux 中将第一行中的一个单词替换为第二行中的另一个单词

`std::cout` 是如何实现的?

如何/在哪里可以找到要修复的 Linux 内核错误?

为什么 Linux (x86) 的页面大小是 4 KB,这是如何计算的?

隐藏文件 .env 未使用 Docker COPY 复制

在 Bash 中识别接收到的信号名称

通过写入 /dev/input/mice 来控制鼠标

用于 GCC/G++ 的宏来区分 Linux 和 Mac OSX?

如何像 Nautilus 那样从命令行挂载?

Linux 和 I/O 完成端口?

从bash中的字符串中删除所有特殊字符和大小写

比较文件的日期 bash

如何运行我所有的 PHPUnit 测试?

Android - 找不到命令

基于shell中正则表达式的 colored颜色 突出显示输出

UNIX `time` 命令对于基准测试是否足够准确?

如何查看线程在哪个 CPU 内核中运行?