5.4.10 · D4 · HinglishMemory Hierarchy & Caches

ExercisesAverage memory access time (AMAT)

3,461 words16 min read↑ Read in English

5.4.10 · D4 · Hardware › Memory Hierarchy & Caches › Average memory access time (AMAT)


Level 1 — Recognition

Goal: har quantity ko pehchano, aur formula padho.

Recall Solution
  • ns — tum hamesha cache ke andar dekhte ho, isliye yeh har access par pay hota hai.
  • — yeh "nahi mila" wala fraction hai.
  • ns — "extra" word hi giveaway hai: yeh look-up se upar ki additional cost hai.

Har access par pay hota hai: . Baki do sirf tab matter karte hain jab miss ho.

Recall Solution

Sahi answer: (b) . Kyun (b) sahi hai — isse do possible outcomes se build karo. Har access ko uske do cases mein split karo aur average lo ("expected time" ki definition yehi hai):

  • Probability ke saath tum hit karte ho aur sirf pay karte ho.
  • Probability ke saath tum miss karte ho: tumne cache mein pehle dekha bhi () aur phir fetch bhi kiya (), isliye pay hota hai. Dono terms cancel ho jaate hain, aur akela khada rehta hai (har access par pay hota hai) aur ko gate karta hai (sirf miss par pay hota hai). Yahi exactly form (b) hai.
  • (a) bhool jaata hai ki miss path par bhi pay hota hai, isliye ek drop ho jaata hai (neeche L1 mistake dekho).
  • (c) galat cheez multiply karta hai — hit time unconditional hai, se gated nahi.
  • (d) bhool jaata hai ki sirf fraction accesses hi penalty pay karte hain.

Level 2 — Application

Goal: single- aur two-level AMAT mein numbers daalo.

Recall Solution

Isko padhte hain: us ns mein se, ns () rare misses se aaya. Rare ≠ cheap.

Recall Solution

Pehle convert karo: .

Recall Solution

Step 1 — ek L1 miss ki cost (= L2 subsystem ka AMAT). Kya: L2 ko uski apni choti cache maano. Kyun: L1 miss ka matlab "DRAM time" nahi, balki "jo bhi L2 subsystem leta hai" woh cost hai. Step 2 — use karo usse L1 mein. Sanity check: ns DRAM trip ko product se scale kiya gaya hai, jo total mein sirf ns add karta hai.


Level 3 — Analysis

Goal: designs compare karo aur reason karo ki kaun sa knob zyaada help karta hai.

Recall Solution

Baseline: ns.

  • A: ns (saved ns).
  • B: ns (saved ns). Winner: B, A se ns zyaada se. Penalty-weighted term ( ns) par attack karna flat ko shave karne se behtar hai, kyunki miss term yahan average ko dominate karta hai.

Neeche wala figure kaise padhen. Yeh ek bar chart hai. Horizontal axis sirf teen designs ke naam hai (Baseline, Option A, Option B) — yeh number line nahi, sirf teen labelled slots hain. Vertical axis AMAT in nanoseconds hai. Har bar ki height us design ka computed AMAT hai, jiska exact value upar likha hai: Baseline , A , B . Do bars black hain (Baseline aur A); ek red bar Option B hai — accent colour winner mark karta hai, aur tum ek nazar mein dekh sakte ho yeh sabse chota bar hai. Heights vertically compare karo: A barely Baseline se neeche jaata hai (flat shave karne se top sirf ns neeche aata hai), jabki B kaafi neeche girta hai ( halve karne se penalty term ke ns hat jaate hain).

Figure — Average memory access time (AMAT)
Recall Solution

Old: ns. New: ns. Worth it — barely ( ns). Miss saving ( ns drop) rise ( ns) se zyaada hai. Yeh Cache Associativity & Hit Time tradeoff in action hai: lower tumhe cost kar sakta hai, aur dono ko weigh karna padta hai.

Turning point: agar new badhkar ns ho jaata, toh new AMAT — trade lose ho jaata.


Level 4 — Synthesis

Goal: AMAT ko doosre formulas (CPU time, local/global rates) ke saath combine karo.

Recall Solution

(a) . (b) L2 sirf woh forwarded accesses dekhta hai: . (c) Global = woh misses jo DRAM tak pahunche, sab accesses par: . Check: ✅. Isliye recursive AMAT nested term ke andar local rate use karta hai — L2 ko un accesses ki khabar nahi jo L1 ne satisfy kar diye. Dekho Multi-level Cache Hierarchy.

Recall Solution

Pehle, is problem ke borrowed symbols define karo (yeh CPU Performance Equation se aate hain):

  • CPI = cycles per instruction = ek instruction finish karne mein CPU average mein kitne clock cycles spend karta hai.
  • = woh CPI jo tumhe milta agar memory free ho (har access L1 hit, koi stall nahi) = yahan .
  • = effective (real) CPI, memory misses ka intezaar karne mein CPU ke barbaad hue cycles add karne ke baad.
  • ns/cycle = clock period, ns — ek cycle ki wall-clock duration. Ns mein time ko ns/cycle se divide karne par cycles ki count milti hai (ns cancel ho jaate hain).

Step 1 — stall time per access. Kya: AMAT ka extra (stall) wala hissa. Kyun: flat pipeline ke base CPI mein already covered hai (CPU har cycle ek L1 hit assume karta hai), isliye sirf penalty term hi ek saccha stall hai. Step 2 — stall time per instruction. Kya: per-access stall ko accesses per instruction se multiply karo. Kyun: har instruction average mein memory accesses issue karta hai, aur har ek mein same expected ns stall hai, isliye stalls add up hote hain — instruction per total stall time hai (stall per access) (accesses per instruction). Step 3 — ns ko cycles mein convert karo. Kyun: CPI cycles mein measure hota hai, isliye stall time ko clock period ( ns/cycle) se divide karo; ns units cancel ho jaate hain, cycles bachte hain. Step 4 — effective CPI. Kya: stalls ko base par add karo. Kyun: real CPI = woh kaam jo CPUaise bhi karta plus woh cycles jisme woh memory ka intezaar karta hua idle baithta hai. Yeh CPU Performance Equation ka bridge hai: AMAT ka penalty term memory-stall cycles ban jaata hai.


Level 5 — Mastery

Goal: formula ko ulta karo, target ke liye design karo, aur limits par reason karo.

Recall Solution

Formula ko limit par set karo aur ke liye solve karo: Toh . Isse zyaada hoga toh ns budget blow ho jaayega. Note: agar akele hi ns exceed kar leta, toh koi miss rate (yahan tak ki ) target meet nahi kar sakta — flat cost pehle se hi fail hai.

Recall Solution

(a) (perfect cache, hamesha hit): . Penalty gayab ho jaati hai — best case; tum sirf look-up pay karte ho. Yeh wahi "perfect cache" baseline hai jo L4-Q2 mein use hua. (b) (kabhi hit nahi — har access miss): . Tum look-up aur full fetch har baar pay karte ho. Worst case. (c) : kisi bhi ke liye . Ek tiny miss rate bhi, agar penalty unbounded ho, average time ko explode kar deti hai — "rare but ruinous" regime yehi hai jise AMAT expose karne ke liye banaya gaya hai. (d) : . Floor sirf miss cost hi hai; cache ko infinitely fast banana bhi penalty-weighted term ko beat nahi kar sakta.

Neeche wala figure kaise padhen aur formula se jodein. Horizontal axis miss rate hai, (left) se (right) tak — yeh ek genuine number line hai. Vertical axis AMAT in ns hai, jisme ns aur ns fixed hain. Kyunki m mein linear hai (ek "" straight line), red curve ek straight line hai jiska kisi bhi par height literally hai. Trace karo: left endpoint () height ns par baithta hai — yeh case (a) hai, jahan term zero hai aur sirf look-up bacha hai. Right endpoint () height ns tak pahunchta hai — yeh case (b) hai, full look-up-plus-fetch worst case. Line ki slope (jitna fast yeh right jaane par rise karta hai) ke equal hai, ns per unit of : bada (case c) line ko steeper karta hai infinity ki taraf; shrink karna (case d) poori line seedha neeche slide kar deta hai origin ki taraf, slope badlay bina.

Figure — Average memory access time (AMAT)
Recall Solution

Subtract karo; common aur factor comparison mein cancel ho jaate hain: Isko padhte hain: L2 tab help karta hai iff uska hit time DRAM penalty se chota ho, jo L2 ke hit rate se scale ki gayi ho. Kyunki DRAM slow hai (hundreds of ns) aur L2 hit time chota hai (kuch ns), yeh practically hamesha true hota hai — lekin agar ke paas hota (L2 useless, almost sab kuch miss ho jaata), toh right side ki taraf shrink ho jaata aur L2 actually hurt kar sakta hai (tum bina kisi fayde ke pay karte). Worked check: , , chahiye ✅ — L2 kaafi zyaada help karta hai.


Active Recall

Recall Cover karo aur jawab do
  1. L2-Q3 mein, L1 miss penalty ns nahi, ns kyun hai?
  2. L3-Q1 mein, miss rate halve karna hit time halve karne se kyun jeeta?
  3. "L2 add karna worth it hai" ki exact inequality state karo (L5-Q3).
  4. Memory-stall time kyun hai, poora AMAT kyun nahi (L4-Q2)?
  5. hone par AMAT kya hota hai? hone par?
Jab misses rare hon lekin bada ho, AMAT mein kaun sa term dominate karta hai?
Penalty term phir bhi dominate kar sakta hai — rare ka matlab cheap nahi.
Effective L1 miss penalty in a two-level cache
L2 subsystem ka AMAT, yaani .
Condition for L2 to reduce AMAT
.
Memory-stall time per access
(sirf penalty term, poora AMAT kabhi nahi).
AMAT when
Sirf (perfect cache, best case).
AMAT when
(har access miss, worst case).

Connections

  • Cache Miss Rate & Miss Types (3 Cs)
  • Miss Penalty & Main Memory Latency
  • Multi-level Cache Hierarchy
  • Cache Associativity & Hit Time tradeoff
  • CPU Performance Equation
  • Locality of Reference