A TLB is a small, fast cache that remembers where virtual pages live in physical memory, so the CPU doesn’t have to read the page table from memory on every access.
With virtual memory, every address a program uses is a virtual address. Before the CPU can fetch the data, it must turn that into a physical address (the real location in RAM).
An address is split into two parts:
Virtual address = [ virtual page number (VPN) | offset ]
Physical address = [ physical frame number (PFN) | offset ]
Example (4 KB pages): virtual address 0x3ABC → VPN = 3, offset = 0xABC. The page table says “page 3 is in frame 7”, so the physical address is 0x7ABC.
The page table itself lives in main memory. So without help, every load or store needs:
That makes every memory access twice as slow.
The TLB (Translation Lookaside Buffer) is a tiny, very fast cache inside the CPU that stores recently used page table entries (VPN → frame number). It’s typically only tens to a few thousand entries, and often fully associative.
Analogy: the page table is the full address book in a drawer (main memory). The TLB is a sticky note on your monitor with the few addresses you’ve looked up recently. You check the sticky note first and only open the drawer if the address isn’t there.
There are four possible paths, from fastest to slowest:

Path 1, TLB hit + cache hit: The TLB gives the frame number immediately, the CPU forms the physical address, and the data is found in the cache. This is the common, fast case.
Path 2, TLB hit + cache miss: The translation is fast, but the data isn’t in the cache, so it comes from main memory.
Path 3, TLB miss, page is in memory: The translation isn’t on the “sticky note”, so the CPU (or OS) reads the page table in main memory. The page table says the page is in RAM, so its entry is copied into the TLB and the access is retried, now as a TLB hit.
Path 4, TLB miss, page is NOT in memory (page fault): The page table’s valid bit says the page is on disk. The OS must:
1. load the page from disk into a free frame in memory,
2. update the page table,
3. update the TLB,
4. restart the instruction.
Disk is extremely slow compared to memory, so this costs millions of cycles.
Answer: in the cache or in main memory, never on disk.
A TLB hit only tells you where the page is in physical memory. It says nothing about whether that particular block is in the cache.
It can’t be on disk because the TLB only keeps entries for pages that are currently in physical memory. When the OS moves a page out to disk, it marks the page table entry invalid and removes (invalidates) that page’s TLB entry. So if the TLB has an entry, the page must be in RAM
The slide jumps quickly from “TLB miss” to “page fault”, but they’re different events:

Virtual address
│
▼
TLB ──hit──► physical address ──► cache ──miss──► main memory
│
miss
▼
Page table (in memory)
├─ page in memory ──► update TLB ──► retry (now a TLB hit)
└─ page NOT in memory ──► PAGE FAULT ──► OS loads page from disk
──► update page table + TLB ──► retry
Each virtual memory reference can cause two physical memory accesses
To overcome this problem a high-speed cache is set up for page table entries
Given a virtual address, processor examines the TLB
If page table entry is present (TLB hit), the page frame address is retrieved and the real address is formed
Question: if TLB hit, where can you find the data?
Cache? Memory? Disk?
If page table entry is not found in the TLB (TLB miss), the page number is used to index the process page table which may not in the memory
First checks if page is already in main memory
The TLB is updated to include the new page entry

1. TLB miss
2. Cache miss
3. Page fault
4. Multiple instances of any of these misses can occur for any single instruction

Both sides translate the same virtual address, page 5, offset 502, to the same real address, frame 37, offset 502. They differ in how they find “page 5 → frame 37”.
The page table has one entry for every virtual page, in order. So the page number is used directly as an index:
page 5 → go straight to entry #5 → frame 37
No searching is needed, because entry #5 always belongs to page 5. The entry doesn’t even need to store the page number.
The TLB is tiny and holds only a few recently used pages, in any order (19, 511, 37, 27, 14, 1, 211, 5, 90, …). Page 5 could be in any slot, so:
The entry tagged 5 matches, and it gives frame 37. This is exactly a fully associative cache, where the page number is the tag.
Then: real address = frame number + same offset
Virtual: [ page 5 | offset 502 ]
Real: [ frame 37 | offset 502 ] ← offset is copied unchanged
Why the TLB is usually (fully) associative

TLB misses are expensive (a page table walk), and the TLB is small, so having one comparator per entry is affordable. That’s why TLBs are typically fully associative or highly set associative. It’s the same reasoning as the victim cache.

Any problem with this design w.r.t performance ?
Don’t want TLB in critical path to cache
The problem: the slow, serial path
The cache in this figure is physically addressed: its tags are physical addresses. So the obvious way to access it is:
TLB (translate page #) → get frame # → THEN access the cache
hit time = TLB time + cache time
The TLB lookup sits in the critical path of every load and store, which makes every cache hit slower.
The key observation: the offset bits never change
Translation only changes the page number. The page offset (low 12 bits for a 4 KB page) is identical in the virtual and physical address. So the CPU can start using those bits before translation finishes.
The solution: access the TLB and the cache at the same time
Here is how the figure’s numbers fit together:

Step by step, for one access:
The numbers in the figure:
This design is called virtually indexed, physically tagged (VIPT): the cache is indexed with bits taken from the virtual address, but compared against physical tags.

“Any requirements to use this method?” — Yes
The cache’s index bits and block offset bits must all come from the page offset, the bits that don’t change during translation:
index bits + block offset bits ≤ page offset bits
⇔ cache size ÷ associativity ≤ page size
In other words, one way of the cache must be no bigger than one page.
Why: if even one index bit came from the virtual page number, that bit could be different in the physical address. You’d then read the wrong set before knowing the translation. A related problem: two virtual addresses that map to the same physical address (aliases) could land in different sets, giving two copies of the same data.

How to get a bigger L1 and keep the trick
Solution: Access TLB & cache concurrently
Any requirements to use this method?


you should know how to draw below structure




검산: 합이 주소 길이와 맞는지
가상 주소: TLB tag 43 + TLB index 8 + page offset 13 = 64 ✓
물리 주소 (L1 기준): L1 tag 28 + index 7 + offset 6 = 41 ✓
물리 주소 (L2 기준): L2 tag 19 + index 16 + offset 6 = 41 ✓
64비트 = 가상 페이지 번호 51 | page offset 13
TLB 쪽: 페이지 번호 51비트 = TLB tag 43 | TLB index 8. index 8비트로 TLB 칸 하나를 고르고, 저장된 TLB tag(43)와 비교합니다 (왼쪽 =?). 같으면 TLB hit이고, 그 칸의 TLB data 28비트 = 물리 페이지 번호가 나옵니다.
L1 쪽 (동시에): page offset 13비트 = L1 index 7 | block offset 6. 번역이 필요 없는 비트라 바로 L1 칸을 골라 L1 tag(28)와 data(512)를 읽습니다.
TLB가 준 물리 페이지 번호 28비트(“L1 tag compare address”)와 L1에서 읽은 tag 28비트를 비교합니다 (가운데 =?). 같으면 L1 hit → block offset으로 원하는 워드를 골라 CPU로 보냅니다.
물리 주소 41비트 = 물리 페이지 번호 28 (TLB에서) | page offset 13 (원래 주소에서). 이걸 L2 기준으로 다시 나눕니다: L2 tag 19 | L2 index 16 | block offset 6
index 16비트로 L2 칸을 고르고, 저장된 tag(19)와 비교합니다 (아래 =?). 같으면 L2 hit → 데이터를 L1이나 CPU로 보냅니다.
교과서 원래 그림에는 L1 cache tag <43>로 나와 있는데, 28이 맞습니다 (그래서 고쳐 쓰신 거예요).
L1 tag는 TLB가 준 물리 페이지 번호(28비트)와 비교됩니다. 비교하는 두 값의 길이가 같아야 하니 28비트입니다.
계산으로도 물리 주소 41 − index 7 − offset 6 = 28입니다.
43은 TLB tag 길이와 헷갈린 오타입니다.
왜 L1은 TLB와 동시에, L2는 번역 후에 접근하나
지난번 규칙을 적용하면:
동시 접근 조건: index 비트 + block offset 비트 ≤ page offset 비트

그래서 L1은 VIPT(가상 주소로 index, 물리 주소로 tag 비교)이고, L2는 번역이 끝난 물리 주소로만 접근합니다 (PIPT). L2는 L1 미스 뒤에야 접근하니, 그때는 이미 번역이 끝나 있어서 기다릴 일이 없습니다.
시험에서 숫자가 바뀌어도 이 순서대로 log₂만 하면 됩니다. 예를 들어 TLB가 4-way 256칸이면 TLB index = log₂(256 ÷ 4) = 6, TLB tag = 51 − 6 = 45가 됩니다.
