Skip to content

Commit

Permalink
UPDATE index
Browse files Browse the repository at this point in the history
  • Loading branch information
karminski committed Feb 5, 2025
1 parent c7d8d1e commit 26f1e14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions 20250206-what-is-L1-cache/what-is-L1-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@

(图片来自 wikipedia)

CPU 的 L1 Cache一级缓存是集成在 CPU 芯片上的高速 SRAM用于存储经常访问的数据或指令, 以达到降低访问内存成本的目的
CPU 的 L1 Cache (一级缓存) 是集成在 CPU 芯片上的高速 SRAM, 用于存储经常访问的数据或指令, 以达到降低访问内存成本的目的.

如图是一个 Intel i386 主板, 其中 L1 Cache 集成到了左上角 CPU 内部, 而左下角的 ISSI 芯片则是 L2 缓存
如图, 是一个 Intel i386 主板, 其中 L1 Cache 集成到了左上角 CPU 内部, 而左下角的 ISSI 芯片则是 L2 缓存.

没错在这个时代 L2缓存还是外置的所以当时 L2 坏掉导致电脑无法启动是很正常的现象
没错, 在这个时代 L2缓存还是外置的. 所以当时 L2 坏掉导致电脑无法启动是很正常的现象.

## 基本概念

简单来讲 CPU 在内存中读取或写入时会检查该位置的数据是否已经在缓存中如果存在则CPU将从高速缓存中读取或写入而不是较慢的主内存
简单来讲 CPU 在内存中读取或写入时, 会检查该位置的数据是否已经在缓存中. 如果存在, 则CPU将从高速缓存中读取或写入, 而不是较慢的主内存.

那么数据是怎么同步的呢?通常我们把内存和缓存中互相传输的数据分成固定大小他们的学名叫做 **cache lines** 或者 **cache blocks**
那么数据是怎么同步的呢?通常我们把内存和缓存中互相传输的数据分成固定大小, 他们的学名叫做 **cache lines** 或者 **cache blocks**.

### Cache Entry

**cache line** 从内存复制到缓存时会创建一个 **cache entry****cache entry** 包含复制的数据和内存位置叫做**tag**)。
**cache line** 从内存复制到缓存时, 会创建一个 **cache entry**, **cache entry** 包含复制的数据和内存位置 (叫做**tag**) .

### Cache Hit

当CPU需要读取或者写入数据时CPU先检查 **cache entry** 是否存在如果 **cache entry****tag** (即内存位置)在缓存中则意味着缓存命中 **cache hit**CPU从 **cache entry** 中读取或者写入
当CPU需要读取或者写入数据时, CPU先检查 **cache entry** 是否存在, 如果 **cache entry****tag** (即内存位置)在缓存中, 则意味着缓存命中 **cache hit**, CPU从 **cache entry** 中读取或者写入.

### Cache Miss

当如果 **cache entry****tag** 不在缓存中则意味着缓存未命中**cache miss**CPU 会分配一个新的 cache entry 若缓存已满需根据替换策略淘汰旧条目并从内存中读取数据然后再从 cache entry 中读取或者写入
当如果 **cache entry****tag** 不在缓存中, 则意味着缓存未命中, **cache miss**, CPU 会分配一个新的 cache entry 若缓存已满需根据替换策略淘汰旧条目) 并从内存中读取数据. 然后再从 cache entry 中读取或者写入.


## ✅ 优点
Expand All @@ -41,13 +41,13 @@ CPU 的 L1 Cache(一级缓存)是集成在 CPU 芯片上的高速 SRAM,用
## ❌ 局限

- 硅片面积成本高
- 容量限制导致缓存颠簸cache thrashing
- 一致性维护开销MESI协议
- 容量限制导致缓存颠簸 (cache thrashing)
- 一致性维护开销 (MESI协议)

## 架构差异比较
| 特性 | x86 (Intel Core) | ARM (Cortex-X) | RISC-V (SiFive) |
|-----------|------------------|----------------|-----------------|
| 典型容量 | 32KB+32KB | 64KB+64KB | 可配置16-128KB |
| 典型容量 | 32KB+32KB | 64KB+64KB | 可配置 (16-128KB) |
| 关联度 | 8-way | 2-way L1 指令, 4-way L1 数据 | 2-8 way可选 |
| 替换策略 | LRU | 伪随机 | 可编程策略 |
| 预取器 | 自适应 | 静态模式 | 可选模块 |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ by @karminski-牙医
- [为什么有的 NVMe SSD 有 DRAM, 有的没有?](20250124-why-some-NVMe-SSD-have-DRAM-and-some-are-not/why-some-NVMe-SSD-have-DRAM-and-some-are-not.md) - 为什么有的 NVMe SSD 有 DRAM, 有的没有?
- [CLX 会是大语言模型的内存解决方案吗?](20250125-does-CXL-will-be-LLM-memory-solution/does-CXL-will-be-LLM-memory-solution.md) - 什么? PCIe 上能插内存了?
- [什么是 1DPC](20250131-what-is-1DPC/what-is-1DPC.md) - 什么是 1DPC? 为什么内存条要插在远端插槽?
- [什么是 L1 缓存](20250206-what-is-L1-cache/what-is-L1-cache.md) - 什么是 L1 缓存? 它的工作原理是什么?

## 贡献

Expand Down

0 comments on commit 26f1e14

Please sign in to comment.