Documentation/translations/zh_CN/mm/page_tables.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/mm/page_tables.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/mm/page_tables.rst- Extension
.rst- Size
- 12124 bytes
- Lines
- 222
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
无论调用路径如何,所有架构最终都会调用 `handle_mm_fault()`,该函数通常会调用
`__handle_mm_fault()` 来执行实际分配页表的任务。
如果不幸无法调用 `__handle_mm_fault()` 则意味着虚拟地址指向了无权访问的物理
内存区域(至少对于当前上下文如此)。这种情况会导致内核向该进程发送上述的 SIGSEGV
信号,并引发前面提到的后果。
这些用于查找偏移量的函数名称通常以 `*_offset()` 结尾,其中“\*”可以是 pgd,p4d,
pud,pmd 或者 pte;而分配相应层级页表的函数名称是 `*_alloc`,它们按照上述命名
约定以对应页表层级的类型命名。
页表遍历可能在中间或者上层结束(PMD,PUD)。
Linux 支持比通常 4KB 更大的页面(即所谓的 `巨页`)。当使用这种较大的页面时,没有
必要使用更低层的页表项(PTE)。巨页通常包含 2MB 到 1GB 的大块连续物理区域,分别由
PMD 和 PUD 页表项映射。
巨页带来许多好处,如减少 TLB 压力,减少页表开销,提高内存分配效率,以及改善
特定工作负载的性能。然而,这些好处也伴随着权衡,如内存浪费和分配难度增加。
在遍历和分配的最后,如果没有返回错误,`__handle_mm_fault()` 最终调用 `handle_pte_fault()`
通过 `do_fault()` 执行 `do_read_fault()`、 `do_cow_fault()` 和 `do_shared_fault()`。
“read”,“cow”和“shared”分别暗示了它处理错误的类型和原因。
实际的工作流程实现是非常复杂的。其设计允许 Linux 根据每种架构的特定特性处理缺页
异常,同时仍然共享一个通用的整体结构。
为了总结 Linux 如何处理缺页中断的概述,需要补充的是,缺页异常处理程序可以通过
`pagefault_disable()` 和 `pagefault_enable()` 分别禁用和启用。
许多代码路径使用了这两个函数,因为它们需要禁止陷入缺页异常处理程序,主要是为了
防止死锁。
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.