Documentation/translations/zh_CN/core-api/cachetlb.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/core-api/cachetlb.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/core-api/cachetlb.rst- Extension
.rst- Size
- 16437 bytes
- Lines
- 334
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- 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
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/core-api/cachetlb.rst
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
:校译:
吴想成 Wu XiangCheng <bobwxc@email.cn>
.. _cn_core-api_cachetlb:
======================
Linux下的缓存和TLB刷新
======================
:作者: David S. Miller <davem@redhat.com>
*译注:TLB,Translation Lookaside Buffer,页表缓存/变换旁查缓冲器*
本文描述了由Linux虚拟内存子系统调用的缓存/TLB刷新接口。它列举了每个接
口,描述了它的预期目的,以及接口被调用后的预期副作用。
下面描述的副作用是针对单处理器的实现,以及在单个处理器上发生的情况。若
为SMP,则只需将定义简单地扩展一下,使发生在某个特定接口的副作用扩展到系
统的所有处理器上。不要被这句话吓到,以为SMP的缓存/tlb刷新一定是很低
效的,事实上,这是一个可以进行很多优化的领域。例如,如果可以证明一个用
户地址空间从未在某个cpu上执行过(见mm_cpumask()),那么就不需要在该
cpu上对这个地址空间进行刷新。
首先是TLB刷新接口,因为它们是最简单的。在Linux下,TLB被抽象为cpu
用来缓存从软件页表获得的虚拟->物理地址转换的东西。这意味着,如果软件页
表发生变化,这个“TLB”缓存中就有可能出现过时(脏)的翻译。因此,当软件页表
发生变化时,内核会在页表发生 *变化后* 调用以下一种刷新方法:
1) ``void flush_tlb_all(void)``
最严格的刷新。在这个接口运行后,任何以前的页表修改都会对cpu可见。
这通常是在内核页表被改变时调用的,因为这种转换在本质上是“全局”的。
2) ``void flush_tlb_mm(struct mm_struct *mm)``
这个接口从TLB中刷新整个用户地址空间。在运行后,这个接口必须确保
以前对地址空间‘mm’的任何页表修改对cpu来说是可见的。也就是说,在
运行后,TLB中不会有‘mm’的页表项。
这个接口被用来处理整个地址空间的页表操作,比如在fork和exec过程
中发生的事情。
3) ``void flush_tlb_range(struct vm_area_struct *vma,
unsigned long start, unsigned long end)``
这里我们要从TLB中刷新一个特定范围的(用户)虚拟地址转换。在运行后,
这个接口必须确保以前对‘start’到‘end-1’范围内的地址空间‘vma->vm_mm’
的任何页表修改对cpu来说是可见的。也就是说,在运行后,TLB中不会有
‘mm’的页表项用于‘start’到‘end-1’范围内的虚拟地址。
“vma”是用于该区域的备份存储。主要是用于munmap()类型的操作。
提供这个接口是希望端口能够找到一个合适的有效方法来从TLB中删除多
个页面大小的转换,而不是让内核为每个可能被修改的页表项调用
flush_tlb_page(见下文)。
4) ``void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)``
这一次我们需要从TLB中删除PAGE_SIZE大小的转换。‘vma’是Linux用来跟
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.