image.png

Virtual Memory

Virtual Address Space

Programs share main memory (Multi-programming and I/O)

Program executed in a namespace (virtual address space) different from the memory space (physical address space).

Each gets a private virtual address space holding its code and data, starting at address 0, only accessible to itself.

想象一下,每个程序都认为自己拥有从 0 开始的一整块独立的内存区域(这就是虚拟地址空间),但实际上,这些程序最终都要使用同一块物理内存条(物理地址空间)。虚拟地址空间就像是给每个程序画了一个“假想的”独立内存蓝图,而物理地址空间才是真实的硬件内存布局。

虚拟内存virtual memory将虚拟地址空间virtual address space映射到物理内存physical address (映射由CPU硬件(MMU)和操作系统共同管理)

OS provides a page table that translates Virtual Address (VA) to Physical Address (PA). Hardware (MMU) speeds up the translation.

操作系统负责设置好“翻译规则”(映射表),而MMU负责在程序真正访问内存的时候,根据这些规则将虚拟地址快速地转换成物理地址。

Versatile Virtual Memory

image.png

Address Translation

Translation via a page table (fixed-size page, e.g. 4KB)

image.png

Page Tables