5.4.2 · D3 · HinglishMemory Hierarchy & Caches

Worked examplesCache organization (direct-mapped)

2,792 words13 min read↑ Read in English

5.4.2 · D3 · Hardware › Memory Hierarchy & Caches › Cache organization (direct-mapped)

Tumne parking-garage wali picture pehle hi dekhi hai Cache organization (direct-mapped) mein: har memory address ke liye ek hi cache line hoti hai jahan woh reh sakta hai. Yeh page woh boring-but-essential kaam karta hai: hum woh ek rule lete hain aur use har tarah ke input se uthate hain jab tak exam mein kuch bhi surprise na kare.

Shuru karne se pehle, teen words jo hum baar baar use karenge, har ek address se hi nikla hua.

Address ko slice hote dekho:

Figure — Cache organization (direct-mapped)

Agar koi word yahan shaky lag raha hai, toh parent note har field ko scratch se derive karta hai; aur Memory Addressing explain karta hai ki addresses ko bytes mein kyun count kiya jaata hai.


Scenario matrix

Direct-mapped cache chhota hota hai, isliye qualitatively alag cheezein jo ho sakti hain ki list finite hai. Yeh rahi — neeche har worked example us cell(s) ke saath tagged hai jise woh cover karta hai.

Cell Kya ise alag banata hai Covered by
A. Cold access Pehli baar touch, valid bit = 0 Ex 1
B. Hit Line valid hai, tag match karta hai Ex 1, Ex 2
C. Same block, different offset Do addresses, same index+tag, alag byte Ex 2
D. Conflict miss / thrash Same index, alag tag, alternating Ex 3
E. Degenerate: block size = 1 , offset field bilkul nahi Ex 4
F. Degenerate: one line , sab kuch line 0 pe map hota hai Ex 4
G. Boundary: block-crossing access Ek read jo do blocks mein span kare Ex 5
H. Wrap-around of index Block wapas line 0 pe aa jaata hai Ex 6
I. Parameter derivation Given sizes → nikalo Ex 7
J. Real-world word problem Array pe loop, misses count karo Ex 8
K. Exam twist Ek parameter badlo, effect predict karo Ex 9

Examples 1–3 aur 5–6 ke liye hum same tiny cache rakhte hain taaki numbers familiar rahein.


Worked examples

Example 1 — Cold access, phir ek hit (cells A, B)

Example 2 — Same block, different offset (cells B, C)

Example 3 — Conflict miss aur thrashing (cell D)

Figure — Cache organization (direct-mapped)

Example 4 — Do degenerate caches (cells E, F)

Example 5 — Block-crossing access (cell G)

Example 6 — Index wrap-around (cell H)

Figure — Cache organization (direct-mapped)

Example 7 — Parameter derivation (cell I)

Example 8 — Real-world word problem (cell J)

Example 9 — Exam twist: ek knob badlo (cell K)


Recall Pure matrix pe quick self-test

Kaun sa field hit vs miss decide karta hai? ::: Tag aur Index dono milke (valid bit ke saath); offset kabhi nahi karta. Cache mein empty lines hote hue bhi har baar miss kyun ho sakta hai? ::: Direct-mapping colliding blocks ko ek hi line pe force karta hai (conflict/thrash), free lines ignore karke — cell D. Agar block size byte ho, kaun sa field gayab hota hai? ::: Offset () — cell E. Block size double karo, cache size fixed rakho: tag ka kya hota hai? ::: Woh same rehta hai; offset , index cancel ho jaate hain — cell K. 0x1F pe ek 4-byte word read ke liye kitne block fetches chahiye? ::: Do — yeh ek block boundary straddle karta hai (cell G).

Related deeper dives: Cache Replacement Policies (kya evict karein jab lines share hoon — direct-mapped ke liye trivial, sirf ek candidate!), Cache Write Policies (ek write hit/miss pe kya hota hai), aur Set-Associative Caches (Example 3 ki thrashing ka ilaaj).