5.4.3 · D1 · HinglishMemory Hierarchy & Caches

FoundationsSet-associative and fully associative caches

2,146 words10 min read↑ Read in English

5.4.3 · D1 · Hardware › Memory Hierarchy & Caches › Set-associative and fully associative caches

Parent note set-associative and fully associative caches padhne se pehle, tumhe har woh symbol khud se banana aana chahiye jo woh tumhare saamne phenk deta hai. Yeh page har ek cheez ko bilkul scratch se build karta hai — pehle plain words, phir ek picture, phir kyun is topic ko yeh cheez chahiye. Upar se neeche padho; har block sirf wahi cheez use karta hai jo usse upar define ho chuki hai.


0. Sab kuch ke peeche ki picture: memory ek giant ruler ki tarah

Is chapter ki har cheez ek idea par tiki hai: memory numbered boxes ki ek lambi line hai, har box mein ek byte (8 bits) hai. Ek box ka number uska address hai.

Figure — Set-associative and fully associative caches
  • Book = main memory (huge, slow), lakhon numbered boxes.
  • Notebook = cache (tiny, fast), sirf muthi bhar boxes.
  • Poora game: book ka ek chunk notebook mein copy karo taaki CPU use jaldi padh sake.

Yeh picture apne dimag mein rakho. Neeche har symbol iska koi na koi hissa label karta hai.


1. Bit, byte, aur "yeh kitni cheezein count kar sakta hai?"

Hum kyun care karte hain? Kyunki addresses bits mein likhe jaate hain, aur bits ki tadaad humein batati hai ki kitne boxes ko naam de sakte hain.

  • bits patterns.
  • bits patterns.
  • bits billion — isliye "32-bit address" lagbhag 4 GB boxes naam de sakta hai.

2. Exponent aur uska undo:

Humne abhi use kiya ("do ko baar khud se multiply karo"). Topic ko baar baar ulta sawaal chahiye hota hai:

"Mere paas cheezein naam deni hain. Mujhe kitne bits chahiye?"

Woh sawaal ==== (log base 2) se answer hota hai.

Yahi tool kyun, na ki ordinary division ya ordinary logarithm? Kyunki hardware addresses bits se bane hain, aur har bit ek doubling hai. Doublings count karna exactly wahi kaam hai jo karta hai — koi aur function "how many bit-switches?" ka jawab nahi deta.


3. Hexadecimal — bits ka ek shorthand

Bits ki lambi strings bahut painful hoti hain. Hexadecimal ("hex") 4 bits ko ek symbol mein pack karta hai, aur phir ke liye use karke. Hex numbers 0x prefix ke saath likhe jaate hain.

Figure — Set-associative and fully associative caches

Topic ko iska kyun zaroorat hai: 0x001A4C0 jaisi addresses bits-strings hi hain disguise mein. Address ko pieces mein split karne ke liye hex bits convert karo, kaato, aur padho.


4. Address, aur usse teen pieces mein kaatna

CPU ek byte ko uske address se maangta hai: ek fixed-width bit number (yahan bits wide, = "address width"). Cache saari bits ko equally treat nahi karta — yeh address ko slice karke teen named fields mein baant deta hai.

Figure — Set-associative and fully associative caches

Picture mein slice ko least-significant (rightmost) se pehle padho, kyunki low bits ruler par chalte waqt sabse tezi se change hote hain:

Teen pieces kyun, na ki ek? Kyunki ek cache slot ko teen alag sawaalon ka jawab dena hota hai: block ke andar kahan? (offset), kaun si shelf dhundhuun? (index), kya yeh sach mein wahi block hai jo mujhe chahiye tha? (tag). Har sawaal ko apne bits milte hain.


5. Block aur block size

Why copy a whole bundle instead of one byte? Spatial locality — programs lagbhag hamesha jald hi neighbouring boxes use karte hain, toh bundle le lena future trips bachata hai.

  • = block size bytes mein (jaise ).
  • Offset bits . ke saath, : exactly itne ki andar ke bytes mein se kisi ko bhi naam de sako.

6. Line, cache size , aur total lines

  • = total cache size bytes mein.
  • Lines ki total tadaad:

Kyun? Har line exactly bytes store karti hai, aur bytes ki jagah hai, toh lines fit hoti hain. Picture mein, chhoti notebook ko equal shelves mein kaato.


7. Sets , ways , aur associativity

Ab parent note ka star. Hum lines ko sets mein group karte hain.

Figure — Set-associative and fully associative caches

Yeh formula kyun? Tumhare paas shelves hain; tum unhe - karke bundle karte ho; bundles ki tadaad hai. substitute karo toh milta hai.

Teen cases seedha picture se padho:

Naam Sets Ek block reh sakta hai…
direct-mapped exactly 1 shelf mein
-way set-associative apne set mein kisi bhi slots mein
fully associative kahin bhi
  • Index bits sets mein se ek pick karne ke liye enough bits.
  • Jab (fully associative), : koi index field hi nahi. Isliye parent ke fully-associative address mein sirf tag + offset hota hai.

Direct-mapped extreme ko Direct-mapped caches mein aur develop kiya gaya hai; miss-type payoff ka subject Conflict misses vs capacity misses mein hai.


8. Comparator aur "parallel"

Kyun matter karta hai: ek -way set ko comparators chahiye; lines ke fully-associative cache ko comparators chahiye. Hardware ka yeh badhta hua dher associativity ki keemat hai, aur yahi parent note ke tradeoff table ko drive karta hai.


9. Tag bits, assembled

Sections 4–7 ko milao toh parent ki master equation milti hai:


Prerequisite map

Bit and byte

Powers of two 2^n

log2 how many bits

Address width A

Hexadecimal shorthand

Split address tag index offset

Block size B

Total lines L equals C over B

Sets S and ways N

Comparators in parallel

Tag bits t

Set-associative and fully associative caches

Related topics jo inhi foundations par build karte hain: Cache replacement policies, Cache performance metrics, Write policies, Cache coherence, Translation Lookaside Buffer (TLB). Hinglish prefer karte ho? Dekho 5.4.03 Set-associative and fully associative caches (Hinglish).


Equipment checklist

Right side cover karo; kya tum reveal karne se pehle har sawaal answer kar sakte ho?

bits kitne patterns represent kar sakte hain?
patterns — har bit count ko double karta hai.
kaunsa sawaal answer karta hai?
"1 se tak pahunchne ke liye mujhe kitni baar double karna hoga?" — yaani cheezein name karne ke liye kitne bits chahiye.
KB mein kitne bytes hote hain?
bytes .
Ek hex digit kitne bits encode karta hai?
Exactly bits ( values mein se ek).
Address jin teen fields mein split hota hai unhe low to high naam batao.
Block offset, set index, tag.
Block aur line mein kya fark hai?
Block bytes ka data hai; line woh physical slot hai (plus tag + valid bit) jo use hold karta hai.
Total lines ka formula?
.
Sets ki tadaad ka formula?
.
Associativity physically kya matlab rakhta hai?
Har set ke andar ways (slots) ki tadaad jahan ek given block baith sakta hai.
Fully associative cache mein index bits kyun nahi hote?
Kyunki hai, toh — sirf ek "set" hai, poora cache.
Tag bits ka formula?
.
Valid bit kya karta hai?
Yeh mark karta hai ki ek line mein real data hai () ya empty garbage (); tag match tabhi HIT count hoti hai jab valid ho.
Higher associativity mein zyada hardware kyun lagta hai?
Isme har way ke liye ek comparator chahiye, jo har lookup mein parallel chalte hain.