Caching Mapping / 缓存映射

Cache映射的三种方式,全相联(Fully Associative cache),直接相连(Direct-Mapped cache),组映射(k set-associative cache)


Cache line

Data is transferred between memory and cache in blocks of fixed size, called cache lines or cache blocks. When a cache line is copied from memory into the cache, a cache entry is created. The cache entry will include the copied data as well as the requested memory location (called a tag).

Fully associative cache

内存块可以放入任意cache line, 所谓见缝插针。


Direct-Mapped cache

每个内存块只能被放入固定的cache line. 例如主存有M块, cache line有C个。
那么内存块n会被装入cache line index = n mod C

优点: 寻找cache时,可以直接从内存块地址计算出cache line。 缺点: 同余的内存块争抢cache line, cache 利用率和命中率低(conflict miss)

k Set-Associative cache

cache line 被划分为k个一组, 内存块通过直接相连映射到cache line组,而在组内使用全相连。

e.g. cache line 被分为 G = C/k 组。
内存块n 对应cache set index = n mod G
在该组的k个cache line 中,可以选择任意位置存放。

优点:前面两种的trade-off 缺点:conflict miss 仍然存在

Jun 8, 2021

[+] click to leave a comment [+]
the comment system on this blog works via email. The button
below will generate a mailto: link based on this page's url 
and invoke your email client - please edit the comment there!

[optional] even better, encrypt the email with my public key

- don't modify the subject field
- specify a nickname, otherwise your comment will be shown as   
- your email address will not be disclosed
- you agree that the comment is to be made public.
- to take down a comment, send the request via email.


Fun with Image Maps and SVGs via benji February 20, 2024

Over the past few weeks I've been playing around with making some images on my website interactive. My "informatics" class in high school taught us some basic HTML. By basic I mean in notepad and writing everything by hand, saving to a...

Goblin Week 2024 via Helvetica Blanc January 26, 2024

It snuck up on me, but I managed to draw my little goblins to celebrate the week! I love my children - they're like awful Pikmin. I've uploaded the whole parade as a print, as well as individual prints for each goblin. There's something very fu…

How to trust gpg keys via Travis Shears Personal Site October 27, 2023

After moving some GPG keys to a new computer I kept getting these trust warnings. It is NOT certain that the key belongs to the person named in the user ID.If you * really * know what you are doing, you may answer the next question with yes. Use this key a…

Generated by openring from webring