惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
美团技术团队
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
L
LangChain Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
腾讯CDC
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
博客园 - 司徒正美
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
C
Check Point Blog
小众软件
小众软件
V
Visual Studio Blog
V
V2EX
F
Full Disclosure
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
人人都是产品经理
人人都是产品经理
量子位
Apple Machine Learning Research
Apple Machine Learning Research
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
博客园_首页
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
Recorded Future
Recorded Future
G
Google Developers Blog
Vercel News
Vercel News
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
爱范儿
爱范儿
Jina AI
Jina AI

Miya's Blog

博客大修记录 (2026) 我在用什么? 记一次软件源归档导致的 CI 构建问题 Denoising Diffusion Null-Space Model 可逆神经网络 Invertible Diffusion Model 常见推理后端安装及配置 Jupyter Notebook 安装及配置 论文复现 - MAGIS 浅谈非易失内存 深度学习环境配置(一) 深度学习环境配置(二) Debian 配置 V2Ray-A Diffusion 入门 CV 基础(二) CV 基础(一) 内存体系结构 - 简述 Programming Persistent Memory 第三章笔记 CuBase 小记
地址映射与TLB
Miya · 2025-04-11 · via Miya's Blog

超标量处理器设计 第三章 地址映射

Overview

We introduce Virtual Memory for the following focuses:

  • Capacity of Physical Memory Devices are not decoupled from address space determined by ISAs.
  • Memory-access with physical address (PA) only is not a easy task for programmers and compilers.
  • Poor scalability, not conducive to scheduling.

With virtual memory, programs always think that they have exclusive access to the address space and therefore do not need to consider address restrictions.

Protection

Another purpose of using VM is permissions and protection. Programs’ access to data is isolated because their virtual address spaces are different, even though they appear to be accessing the same address.

Sharing

Program segments and data segments shared by multiple programs do not need to be copied multiple times, and the OS will link them to the same physical address, e.g., printf(). This saves physical memory device capacity and avoids Memory Bloat.

Address Translation

In this section, we will talk about Paging, the most commonly used implemention of virtual memory model.

In a paging scheme, the virtual address space is divided into pages, while the physical address space is divided into frames, they both represent a data block. The sizes of a page and a frame should be the same ( ? I think these can be decoupled).

Demand Paging

Pages are loaded into physical memory only when they are needed. Suppose that a program is allowed to use a virtual address (called VA0), but before VA0 is actually accessed the addressed, the VA → PA mapping is not established and there is no corresponding PTE. Not until a Page Fault occurs does the OS know it should fetch data from disks and put them into memory devices.

This brings below advantages:

  • Avoid redundant memory usage, traffic and bandwidth consumption.
  • Allow the processor to run programs that are larger than the memory device can hold by decoupling physical capacity and memory space.

For example, mapping of 4KB pages is likely to be:

1
2
3
4
5
(VPN ─► PFN)        (Program Calculates)        ▬ VPN: Virtual Page Number
┌───────────────────┬────────────────────┐ ▬ PFN: Physical Frame Number
│ VPN │ offset │
├───────────────────┼────────────────────┤
│31 12|11 ◄──── 2^12 ───► 0│

(32-bit ISA; P & F are of the same size.)

Single-level PT

TLB

TLB in MIPS32

MIPS32 中存在以下与 TLB 有关的寄存器

  • EntryHi
  • EntryLo {0/1}
  • Index

EntryHi 用于检查是否 TLB Hit,主要包含 VPN 和 ASID ( 用于检查地址空间是否一致 ),每个 EntryHi 对应两个 EntryLo. MIPS32 用位掩码支持可变页大小,一般地,一个 VPN 对应两个 PFN.

Index 用于标识当前 TLB 查找命中的索引,在填入 TLB 时,这个寄存器用于标识待替换的表项。

程序通过以上 TLB 寄存器与 TLB 进行交互,MMU 做地址翻译也是根据 TLB 寄存器,因此某种程度上,这可被看是 TLB 缓存。更新时,首先写入通用寄存器,再通过特权移动指令,移动到 TLB 寄存器。而 MIPS32 的页表由 OS 管理,在处理缺页等软件处理异常时,可通过 TLB 指令与 TLB 交互。

  • TLBWI: 将 TLB CP0s 中的内容写入 TLBindex
  • TLBWR: 将 TLB CP0s 中的内容写入 TLBrandom
  • TLBR: 将 TLBindex 中的内容写入 TLB CP0s
  • TLBP: 将使用 EntryHi 在 TLB 中的查询结果写入 Index

PTBR

页表基址寄存器,如 CR3 (in x86),在加速缺页处理过程中起重要作用。MIPS32 只有 Context 寄存器。MIPS64 XContext 寄存器,用来扩展虚拟地址空间 (up-to-40-bit)

Context 保存了想要保存的内存页表基址。该基地址的低 22 位为 0,也就是以 4M 为边界。虽然在物理内存或者未映射的内存上提供对齐很低效,但是这样设计的目的是把该表存储到 kseg2 ( 我们以前提到过 ) 映射区域内。主要辅助 TLB Refill 重填,当发生 TLB Miss 需要重填时,在 PTE Base 指向的区域取匹配的表项进行快速回填。

references[1] [2]


  1. https://tupelo-shen.github.io/2020/06/17/MIPS架构深入理解5-内存管理/ ↩︎

  2. MIPS32地址映射和TLB - 者旨於陽 - 博客园 ↩︎