Recall Feynman: ek 12-saal ke bachche ko explain karo
Imagine karo ek shop mein 4 checkout lines (CPUs) hain. Har shopper (task) ka saaman already ek specific lane ke paas rakha hua hai (yeh cache hai — unka data wahan "warm" hai). Agar ek lane mein badi bheed hai aur doosri khaali hai, toh aap logon ko khaali lane mein bhej sakte ho — lekin unhe apna sara saaman carry karna padega, jisme time lagta hai. Toh rule simple hai: kisi ko nayi lane mein tabhi bhejo jab purani lane mein unka wait nayi lane tak jaane ki jhanjhat se zyada ho. Yahi hai load balancing (khaali lanes mein bhejo) aur affinity (saaman wahan warm hai jahan ho) ka aapas mein ladna.
CPU Scheduling Basics — single-CPU algorithms jinhe yeh generalize karta hai (RR, priority).
Cache Memory and Locality — affinity kyun matter karta hai (hot vs cold cache, working set).
NUMA Architectures — affinity memory-node locality tak extend hoti hai, sirf cache tak nahi.
Linux CFS Scheduler — real MQMS + periodic balancing (sched_domains, imbalance_pct).
Spinlocks and Lock Contention — SQMS ke single queue lock ke scale na karne ki wajah.
Context Switching Cost — migration cost M, switch + cache reload par build karta hai.
Multiprocessor scheduling mein do competing goals kaun se hain?
Load balancing (sab CPUs equally busy rakho) vs. cache/processor affinity (task ko usi CPU par rakho taaki uska data cache mein hot rahe).
Processor affinity define karo, soft vs hard.
Affinity = preference ki task us CPU par rahe jis par last chala tha, cache warmth ke liye. Soft: scheduler koshish karta hai lekin migrate kar sakta hai. Hard: program ek CPU set force karta hai (jaise sched_setaffinity); scheduler ko maanna padta hai.
Costs se derive kiya hua migrate-or-stay rule kya hai?
Migrate iff W > M, jahan W = busy CPU par bachaayi gayi wait time aur M = migration cost including cold-cache reload penalty.
Push vs pull migration?
Push: ek periodic task loads check karta hai aur overloaded CPUs se tasks push karta hai. Pull: ek idle CPU busy CPU ke queue se ek waiting task pull karta hai.
SQMS — kya hai aur iske drawbacks?
Single-Queue Multiprocessor Scheduling: ek global ready queue. Drawbacks: lock contention (poor scaling) aur koi affinity nahi.
MQMS — kya hai aur iska drawback?
Multi-Queue: har CPU ka ek ready queue; scalable + affinity-friendly lekin queues balance se drift ho jaate hain, explicit load balancing chahiye.
Imbalance Δ = 0 tak balance kyun nahi karte?
Isse migration thrashing hoti hai — tasks CPUs ke beech ping-pong karte hain, caches cold rehte hain; balance sirf threshold ke baad karo (jaise imbalance_pct ≈ 125%).