Is é context switch an kernel ag sábháil staid CPU an snáithe atá ag rith faoi láthair (registers, program counter, stack pointer) agus ag athchóiriú staid snáithe eile, ionas gur féidir le croí amháin go leor snáitheanna a ilphléacsú. Tarlaíonn sé ag gach preemption scheduler, syscall blocála, nó interrupt — agus níl sé saor in aisce.
Cá bhfolaíonn an costas
DIRECT cost (visible, ~1–5 µs):
save/restore registers · run scheduler logic · switch kernel stacks
if PROCESS switch: also swap page tables (CR3) → FLUSHES the TLB
INDIRECT cost (often much larger):
cold CPU CACHES → the new thread's data isn't in L1/L2/L3 → cache misses to RAM
cold TLB → address translations must be re-walked
lost pipeline / branch-predictor state
