# 内存管理单元

内存管理单元（MMU）是一种硬件组件，通常位于处理器内部，负责将软件发出的虚拟地址转换为内存中的物理地址，并强制执行附着在每个转换上的访问权限和内存属性。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup><sup> • </sup><sup>[2](https://github.com/codingbelief/arm-architecture-reference-manual-for-armv8-a/blob/master/en/chapter_d4/d42_1_about_the_vmsav8-64_address_translation_syste.md)</sup> 正是MMU使得分页虚拟内存成为可能：每个进程可以使用自己私有的地址空间，一个进程的代码无法改动另一个进程使用的物理内存，操作系统可以在应用程序毫无察觉的情况下在RAM和磁盘之间搬移数据。<sup>[3](https://learn.microsoft.com/th-th/windows-hardware/drivers/gettingstarted/virtual-address-spaces)</sup>

| 关键事实 | 详情 |
|---|---|
| 核心功能 | 将虚拟地址转换为物理地址，并按内存区域控制内存访问权限、内存排序和缓存策略<sup>[4](https://www.intel.com/content/www/us/en/docs/programmable/814346/24-1/memory-management-unit-88873.html)</sup> |
| 转换缓存 | 转译后备缓冲器（TLB）缓存最近使用过的转换，使后续查找无需重读页表<sup>[5](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/LearnTheArchitecture-MemoryManagement-101811_0100_00_en.pdf?revision=1fdc3375-d81c-4457-b786-04fb98557de0)</sup> |
| 页表 | 以层级结构存放于主存中；Linux定义了五个层级（PGD、P4D、PUD、PMD、PTE），在使用较少层级的架构上，未使用的层级会被折叠掉<sup>[6](https://docs.kernel.org/mm/process_addrs.html)</sup> |
| 故障行为 | 当转换缺失、地址不在物理内存中或访问不被允许时，MMU会引发缺页异常，将控制权转交给操作系统<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup> |
| RISC-V Sv39 | 39位虚拟地址空间；27位虚拟页号通过三级页表转换为44位物理页号，外加12位不参与转换的偏移量<sup>[7](https://docs.riscv.org/reference/isa/priv/supervisor.html)</sup> |
| 大页 | Sv39支持4 KiB页，以及2 MiB的兆页和1 GiB的吉页；x86 Linux支持4K和2M的页大小，若架构支持，还支持1G的页大小<sup>[7](https://docs.riscv.org/reference/isa/priv/supervisor.html)</sup><sup> • </sup><sup>[8](https://docs.kernel.org/admin-guide/mm/hugetlbpage.html)</sup> |
| 历史 | 分页虚拟内存于1962年在Ferranti Atlas计算机上发明，那是第一台具备分页虚拟内存的计算机；该特性于1985年进入Intel 80386<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup> |

## 转换的工作方式

当CPU访问某个内存位置时，它向MMU提供一个虚拟地址，MMU首先检查TLB或页表遍历缓存中是否已存在该转换——后者是较小的缓存，在支持它们的架构上存放页表的中间层级。如果未找到转换，MMU便执行一次页表遍历：逐级读取主存中的页表，以确定物理地址并建立映射。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup> 一次转换始于芯片上的TLB缺少与所请求虚拟地址匹配的条目之时。<sup>[9](https://www.intel.com/programmable/technical-pdfs/654202.pdf)</sup>

页表本身是普通内存。每个条目携带下一级页表的物理地址，或者在叶级携带数据页的物理地址，同时还带有权限标志和脏位等标志——脏位在页被写入时置位，表示该页自载入内存以来已被修改。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup> 层级式页表节省内存并加速映射：稀疏的地址空间只需要它实际使用的那些表层级。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup>

**权限与属性。** 除地址转换之外，MMU还按内存区域控制内存访问权限、内存排序和缓存策略。<sup>[4](https://www.intel.com/content/www/us/en/docs/programmable/814346/24-1/memory-management-unit-88873.html)</sup> Arm架构将MMU描述为对处理单元发起的内存访问进行地址转换控制、内存访问权限控制以及内存属性的判定与检查。<sup>[2](https://github.com/codingbelief/arm-architecture-reference-manual-for-armv8-a/blob/master/en/chapter_d4/d42_1_about_the_vmsav8-64_address_translation_syste.md)</sup>

## TLB及其维护

TLB是转换的缓存，而非转换表的缓存。TLB条目中存放的是在页表被遍历的那一刻、根据当时配置对某个转换表条目所作的解释，因此影响该解释的寄存器字段被描述为允许缓存在TLB中。<sup>[5](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/LearnTheArchitecture-MemoryManagement-101811_0100_00_en.pdf?revision=1fdc3375-d81c-4457-b786-04fb98557de0)</sup> TLB通常是处理器中极为稀缺的资源，操作系统会设法最佳利用数量有限的TLB条目。<sup>[8](https://docs.kernel.org/admin-guide/mm/hugetlbpage.html)</sup>

**软件何时必须无效化。** 处理器不得缓存会导致转换故障（地址未映射）、地址大小故障或访问标志故障的转换。因此，首次映射某个地址时无需进行TLB无效化。而取消某个地址的映射、更改某个映射的输出地址或属性（例如从只读改为读写），或者更改页表的解释方式（例如粒度大小发生变化）时，则需要进行无效化。<sup>[5](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/LearnTheArchitecture-MemoryManagement-101811_0100_00_en.pdf?revision=1fdc3375-d81c-4457-b786-04fb98557de0)</sup> 在RISC-V上，监管态内存管理栅栏指令SFENCE.VMA保证：对当前hart已经可见的先前存储，排在后续指令对内存管理数据结构的隐式引用之前。<sup>[10](https://github.com/riscv/riscv-isa-manual/blob/main/src/priv/supervisor.adoc)</sup>

由于硬件不提供跨核的TLB一致性，修改页表的内存管理操作在高线程化应用中因性能糟糕而臭名昭著，这主要归咎于操作系统必须发出的进程级TLB击落。<sup>[11](https://arxiv.org/abs/2401.15558)</sup>

## 缺页异常

缺页异常是MMU在无法完成访问时引发的异常：地址可能未映射、数据可能不在物理内存中，或者当前任务可能不被允许进行该访问。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup> CPU暂停执行，运行操作系统中的处理程序，由它创建或加载所需的页表和条目，必要时从持久存储请求数据，并更新MMU及其缓存。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup>

许多缺页异常是预期行为而非错误。延迟分配和写时复制等进程管理优化就依赖于它们。故障也可能指示缺陷：线程访问自身地址空间之外的内存，或对只读位置进行写入，都会导致内核发出段错误（SIGSEGV）信号，通常终止该线程及其进程。<sup>[1](https://docs.kernel.org/mm/page_tables.html)</sup>

## 架构示例

**RISC-V。** 特权规范为RV64定义了若干分页虚拟内存系统，以在地址空间大小与转换开销之间取得平衡。Sv39提供39位虚拟地址空间，采用三级页表，每个条目八字节，每张表2<sup>9</sup>个条目。任意一级页表条目都可以是叶条目，2 MiB和1 GiB页正是以此方式得到支持；每一页都必须对齐到与其大小相等的边界，对齐不足会引发缺页异常。Sv48为39位不够用的系统增加了第四级，支持Sv48的实现也必须支持Sv39。satp控制寄存器保存根页表的物理页号、用于按地址空间进行转换栅栏的地址空间标识符（ASID），以及一个MODE字段，用于选择Bare、Sv39、Sv48或Sv57。<sup>[7](https://docs.riscv.org/reference/isa/priv/supervisor.html)</sup><sup> • </sup><sup>[10](https://github.com/riscv/riscv-isa-manual/blob/main/src/priv/supervisor.adoc)</sup>

**Arm AArch64。** Arm MMU使用存放于内存中的转换表，转换表条目可以缓存在TLB中。<sup>[2](https://github.com/codingbelief/arm-architecture-reference-manual-for-armv8-a/blob/master/en/chapter_d4/d42_1_about_the_vmsav8-64_address_translation_syste.md)</sup> 例如，每个Cortex-A55核心都包含一个MMU，负责将虚拟地址转换为物理地址，并控制访问权限、内存排序和缓存策略。<sup>[4](https://www.intel.com/content/www/us/en/docs/programmable/814346/24-1/memory-management-unit-88873.html)</sup>

**x86。** 在x86计算机上，宿主页大小为4千字节，当需要空间时，Windows会将物理内存中最久未使用的页移到磁盘上的分页文件中；这一操作对应用程序是透明的，应用程序只在自己的虚拟地址空间中运行。<sup>[12](https://learn.microsoft.com/en-us/windows/win32/memory/virtual-address-space-and-physical-storage)</sup> Pentium Pro引入了物理地址扩展，为36位物理地址启用了4条额外的地址线，同时在页表条目中引入了全局位，并普遍支持更大的页大小。<sup>[13](https://www.intel.com/content/dam/support/us/en/documents/processors/pentium4/sb/25366821.pdf)</sup>

## CPU之外的MMU

转换硬件并不限于处理器。在[Windows 10](https://www.edgepedia.org/zh/windows-10)（WDDM 2.0）引入的GpuMmu模型中，GPU拥有自己的MMU，将按进程划分的GPU虚拟地址转换为物理地址，由显存管理器负责分配和更新页表；访问无效的GPU虚拟地址范围会引发访问违规，并终止出错的上下文或设备。<sup>[14](https://learn.microsoft.com/en-us/windows-hardware/drivers/display/gpummu-model)</sup> 对于一般设备，Arm系统内存管理单元（SMMU）为具备DMA能力的硬件执行地址转换；在一项研究设计中，SMMU在虚拟地址RDMA期间检测到的故障通过一种软硬件机制来解决，该机制可以在需要时请求重传。<sup>[15](https://arxiv.org/abs/2511.21018)</sup>

## 页大小为何重要

TLB中缓存的每个转换只覆盖一页，因此更大的页让单个TLB条目能够映射更大的内存区域。段和大页正是为了在使用单个TLB条目的同时映射大块区域而得到支持的。<sup>[9](https://www.intel.com/programmable/technical-pdfs/654202.pdf)</sup> Linux通过其大页支持来体现这一点，该支持建立在大多数现代架构提供的多种页大小之上，可通过mmap系统调用或标准的SYSV共享内存调用来使用。<sup>[8](https://docs.kernel.org/admin-guide/mm/hugetlbpage.html)</sup> 权衡也有另一面：使用更大的页会降低典型操作系统内存管理的灵活性。<sup>[9](https://www.intel.com/programmable/technical-pdfs/654202.pdf)</sup>

## References

1. [Page Tables, The Linux Kernel documentation](https://docs.kernel.org/mm/page_tables.html)
2. [About the VMSAv8-64 address translation system, Arm Architecture Reference Manual for Armv8-A (transcription)](https://github.com/codingbelief/arm-architecture-reference-manual-for-armv8-a/blob/master/en/chapter_d4/d42_1_about_the_vmsav8-64_address_translation_syste.md)
3. [Virtual address spaces, Windows drivers documentation, Microsoft Learn](https://learn.microsoft.com/th-th/windows-hardware/drivers/gettingstarted/virtual-address-spaces)
4. [Memory Management Unit, Agilex 5 SoC Hard Processor System Technical Reference Manual, Intel](https://www.intel.com/content/www/us/en/docs/programmable/814346/24-1/memory-management-unit-88873.html)
5. [Learn the Architecture: Memory management, Arm](https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/LearnTheArchitecture-MemoryManagement-101811_0100_00_en.pdf?revision=1fdc3375-d81c-4457-b786-04fb98557de0)
6. [Process Addresses, The Linux Kernel documentation](https://docs.kernel.org/mm/process_addrs.html)
7. [Supervisor-Level ISA, RISC-V Ratified Specifications Library](https://docs.riscv.org/reference/isa/priv/supervisor.html)
8. [HugeTLB Pages, The Linux Kernel documentation](https://docs.kernel.org/admin-guide/mm/hugetlbpage.html)
9. [Memory Management Unit, processor technical reference (ARM-based SoC), Intel](https://www.intel.com/programmable/technical-pdfs/654202.pdf)
10. [riscv-isa-manual, supervisor.adoc, GitHub](https://github.com/riscv/riscv-isa-manual/blob/main/src/priv/supervisor.adoc)
11. [numaPTE: Managing Page-Tables and TLBs on NUMA Systems, arXiv](https://arxiv.org/abs/2401.15558)
12. [Virtual Address Space and Physical Storage, Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/memory/virtual-address-space-and-physical-storage)
13. [Intel 64 and IA-32 Architectures Software Developer's Manual (memory management facilities)](https://www.intel.com/content/dam/support/us/en/documents/processors/pentium4/sb/25366821.pdf)
14. [GpuMmu Model, Windows drivers documentation, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/display/gpummu-model)
15. [Handling of Memory Page Faults during Virtual-Address RDMA, arXiv](https://arxiv.org/abs/2511.21018)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Instruction set architectures › CPU operating modes and ISA-support mechanisms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/memory-management-unit

English original: https://www.edgepedia.org/memory-management-unit
