Exercises — NUMA architectures
6.1.7 · D4· Hardware › Parallelism & Multicore › NUMA architectures
Prerequisites jo tum open rakhna chahoge: 6.1.05-memory-consistencymodels, 6.1.06-multicore-synchronization, 6.2.03-thread-scheduling, 6.3.01-parallel-algorithms.
Level 1 — Recognition
Exercise 1.1
Har phrase ko sahi term se match karo: (a) memory access time kabhi bhi location par depend nahi karta, (b) memory access time location par depend karta hai, (c) NUMA jisme nodes ke across hardware coherence ho.
Options: UMA / SMP, NUMA, ccNUMA.
Recall Solution
- (a) → UMA / SMP — Uniform ka matlab hai ek flat cost.
- (b) → NUMA — Non-uniform: local fast, remote slow.
- (c) → ccNUMA — "cc" hai cache-coherent: caches nodes ke across automatically sync rehti hain.
Kyun: poora subject ek sawaal par split hota hai — kya distance cost ko change karta hai? UMA kehta hai nahi, NUMA kehta hai haan, ccNUMA kehta hai haan aur tumhare liye caches ko honest bhi rakhta hai.
Exercise 1.2
Ek 4-node NUMA machine node 0 se ye latencies report karta hai: local 85 ns, remote 140 ns. Us remote node ke liye NUMA factor batao.
Recall Solution
NUMA factor by definition ratio hai. Factor 1.0 ka matlab hoga "koi penalty nahi" (pure UMA). 1.0 se upar kuch bhi door shelf tak jaane ki cost hai.
Level 2 — Application
Exercise 2.1
Ek application apne 80% accesses locally karta hai. Local latency 85 ns hai, remote 140 ns hai. Average access time nikalo.
Recall Solution
80% local ka matlab hai remote fraction hai. (Formula remote fraction ke terms mein likha gaya hai — inhe mix karo aur har baad ka problem drift karega.) Directly: ns. Dono tarike agree karte hain — bracket form sirf direct sum ko se factor karke hai.
Exercise 2.2
Interleaved mapping use karte hue, cache line size bytes aur ke saath, byte address ko kaun sa node own karta hai?
Recall Solution
Step 1 — yeh byte kis cache line mein hai? Line size se divide karo aur remainder drop karo: Step 2 — line 130 ko kaun sa node hold karta hai? Ise node count se modulo lo (interleaving lines ke across cycle karta hai): Toh address 8320 node 2 par rehta hai.
Kyun pehle floor phir mod: floor ek line ke saare 64 bytes ko ek line number mein collapse karta hai (ek poori line ek node par rehti hai), aur mod consecutive lines ko bandwidth ke liye nodes par round-robin spread karta hai.
Level 3 — Analysis
Exercise 3.1
ke liye, aur par all-remote baseline ke upar speedup compute karo. Gap ko interpret karo.

Recall Solution
measure karta hai ki tumhara mixed workload us disaster case se kitna fast hai jahan har access remote hoti hai. par: par: Interpretation: 80% local se 95% local jaane par sirf zyada milta hai. Curve dekho (figure): yeh ke paas bahut flat ho jaata hai. Remote traffic ke aakhiri kuch percent ko hataana expensive hai aur bahut kam extra deta hai — yeh wahi "last 5%" cost hai jo parent note ne flag ki thi.
Exercise 3.2
Do threads alag-alag nodes par baar baar alag 4-byte words likhte hain jo usi 64-byte cache line mein baithe hote hain. Ek local L3 miss 30 ns cost karta hai; ek 3-hop coherence bounce 300 ns cost karta hai. Agar, isko tune karne ke baad is cheez se bachne ke liye, har write 30 ns ka local hit hoti, toh is false sharing ki wajah se per-write slowdown kya hai?
Recall Solution
False sharing ka matlab hai do words logically independent hain par ek hi coherence unit (line) share karte hain. Har write doosre node ki copy ko invalidate kar deta hai, 3-hop bounce force karta hai: Kyun hota hai: coherence poori lines track karta hai, individual words nahi. Hardware nahi bata sakta ki do threads kabhi same bytes nahi touch karte — woh sirf same line ko ping-pong hote dekhta hai. Fix: har thread ke word ko apni khud ki cache line par pad karo (64 bytes align karo) taaki woh alag coherence units mein jaayein.
Level 4 — Synthesis
Exercise 4.1
Tumhare paas ek workload hai jisme ns aur hai. Tumhara budget tumhe ko zyada se zyada 100 ns tak laane deta hai. Maximum remote fraction kya hai jo tum tolerate kar sakte ho?
Recall Solution
Average-time law ko budget ke barabar set karo aur ke liye solve karo: Toh tum zyada se zyada ≈17.6% remote accesses allow kar sakte ho (≈82.4% local). Isse zyada loose karo aur tum 100 ns budget blow kar doge.
Kyun ke liye solve karein: design question ulta hai — "given a mix, what's the time?" nahi, balki "given a time target, what mix is allowed?" Same equation, rearranged. Yeh OS scheduler ko batata hai ki NUMA placement kitna aggressive hona chahiye.
Exercise 4.2
Matrix-multiply example mein, NUMA-unaware run 12 GB/s deta hai; first-touch + thread pinning ke baad yeh 45 GB/s hit karta hai. (a) Bandwidth speedup kya hai? (b) Agar compute ko 90 GB traffic chahiye, toh har version kitna wall-clock time leta hai, aur NUMA tuning ne kitna bachaya?
Recall Solution
(a) Speedup . (b) Time = data ÷ bandwidth (bandwidth bytes per second mein hai, toh divide karne par seconds milte hain):
- Unaware: s
- Tuned: s
- Bachaya: s.
Kyun first-touch ne fix kiya: OS ek page us node par allocate karta hai jiska thread use pehle write karta hai. Har thread ko apni rows pehle zero karwa ke, hum force karte hain ki thread ke node par live kare — toh baad ki har write local hoti hai, aur interconnect bottleneck rehna band ho jaata hai.
Level 5 — Mastery
Exercise 5.1
Design target: ek 4-node ccNUMA server ko apne flagship app ke liye rakhna hai. Measured hai. (a) Software ko kaunsi locality (local accesses ki percentage ke roop mein) achieve karni chahiye? (b) Agar profiling dikhaye ki app naturally sirf 70% local hit karta hai, toh parent note se do concrete mechanisms batao jo ise line ke upar push kar sakein, aur argue karo ki har ek kyun help karta hai.
Recall Solution
(a) chahiye, matlab bracket : Toh remote fraction zyada se zyada 12.5% hona chahiye, matlab ≥87.5% local.
(b) 70% local () se hume tak pahunchna hai:
- First-touch allocation — pages us node par land karte hain jis thread ne unhe pehle likha, toh ek thread ka working set local ban jaata hai. Remote accesses ko directly local mein convert karta hai.
- Thread pinning
numactl --cpunodebind --membindke zariye — scheduler ko mid-run mein ek thread ko uske data se door migrate karne se rokta hai, jo silently local pages ko remote bana deta. First-touch ne jo affinity establish ki usse lock in karta hai.
Optionally, range-based address mapping (interleaved nahi) wahi hai jo first-touch ko possible banata hai, kyunki yeh OS ko ek thread ko ek contiguous local block dene deta hai.
Exercise 5.2
Prove karo ki speedup formula ka ek hard ceiling hai, aur ki woh value batao jo ise attain karti hai. Phir, ke liye, best possible speedup do.
Recall Solution
tab sabse bada hota hai jab iska denominator sabse chhota ho. Denominator mein ek straight line hai; kyunki hai, badhane se woh kabhi decrease nahi karta. Toh minimum denominator sabse chhote par hota hai, yaani (sab local): Is tarah se zyada nahi ho sakta, aur equality exactly par milti hai (perfect locality). ke liye best possible speedup hai.
Kyun yeh ceiling hai: baseline hai "sab remote." Absolute best jo tum kar sakte ho woh hai "sab local," jo times fast hai — koi tuning physics ko nahi beat kar sakti.
Recall Self-test cloze
Average-time law mein do knobs hain ::: remote fraction aur NUMA factor All-remote ke upar maximum possible speedup barabar hai ::: , par attain hota hai First-touch allocation ek page us node par rakhta hai jo ::: pehle usse write karta hai False sharing ping-pong karta hai kyunki coherence track karta hai ::: poori cache lines, individual words nahi