5.4.15 · D3 · HinglishMemory Hierarchy & Caches

Worked examplesMESI - MOESI coherence protocols

2,849 words13 min read↑ Read in English

5.4.15 · D3 · Hardware › Memory Hierarchy & Caches › MESI - MOESI coherence protocols

Yeh page parent topic ke liye exhaustive drill room hai. Parent ne state machine sikhaya; yahan hum har tarah ki situation walk karte hain jo protocol face kar sakta hai — har state jisse tum start kar sakte ho, har bus event jo tum snoop kar sakte ho, weird zero/degenerate cases (self-writes, evictions, already-invalid lines), aur timing twists jo exam-setters ko bahut pasand hain. Agar tum neeche ke saare cells ka outcome predict kar sako, toh protocol tumhara ho gaya.

Shuru karne se pehle, woh vocabulary jo hum use karenge (sab parent mein define hai, yahan dobara bata rahe hain taaki koi symbol bina explain ke na aaye):

Related reading jo tum doosre tab mein kholna chahoge: Snooping vs Directory-based protocols, Write-back vs Write-through caches, False Sharing, MOESI in AMD, MESIF in Intel.


Scenario matrix

Coherence ek state machine hai, isliye "har scenario" = (starting state) × (event) × (protocol), plus degenerate/timing edge cases. Yeh hai woh complete grid jo hum cover karenge. Har cell us example ka naam deta hai jo us case ko hit karta hai.

Case class Concrete situation Covered by
Cold miss → sole owner Aisa address read karo jो kisi ke paas nahi Ex 1 (step 1)
Cold miss → sharer Aisa address read karo jo kisi aur ke paas hai Ex 1 (step 2)
Silent upgrade E mein likhte hue (zero bus traffic) Ex 2
Write while Shared S se store ko invalidate chahiye Ex 3
Write miss (I→M) Aisi line mein store karo jo tumhare paas nahi Ex 4
Snoop BusRd while M (MESI) Forced write-back, M→S Ex 5
Snoop BusRd while M (MOESI) M→O, cache-to-cache, memory write nahi Ex 6
Owner shares again O line se teesra reader Ex 6 (extension)
Eviction of dirty line O/M evict hona → woh ek memory write Ex 7
Degenerate: self write-write Same core do baar likhta hai, no bus Ex 8
Degenerate: already-I snoop Bus event aisi line par jo tumhare paas nahi Ex 8 (verify)
Real-world word problem Producer/consumer flag Ex 9
Exam twist: false sharing Do variables, ek line, ping-pong Ex 10

Worked examples

Figure — MESI - MOESI coherence protocols
Figure — MESI - MOESI coherence protocols

Active recall

Recall Answers cover karo aur har cell predict karo
  • Fresh line par do reads: final states? ::: Dono S (pehla E gaya, doosre reader par S mein drop hua).
  • E→M silent upgrade ke liye bus messages? ::: 0.
  • S se store kaun sa message use karta hai? ::: BusRdX (doosron ko invalidate karo), phir S→M.
  • M, MESI vs MOESI mein BusRd snoop karta hai? ::: MESI: flush + M→S (memory write). MOESI: M→O, cache-to-cache, koi memory write nahi.
  • Deferred MOESI memory write aakhir kab pay hoti hai? ::: O (ya M) line ke eviction par.
  • False sharing: alag variables hone ke bawajood traffic kyun? ::: Coherence cache line per hota hai, variable per nahi.
  • I line par snoop event? ::: Kuch mat karo — koi data khoone ya invalidate karne ke liye nahi hai.