Sebuah context switch ialah kernel menyimpan keadaan CPU thread yang sedang berjalan (register, program counter, stack pointer) dan memulihkan keadaan thread lain, supaya satu core boleh memultipleks banyak thread. Ia berlaku pada setiap perampasan scheduler, blocking syscall, atau interrupt — dan ia tidak percuma.
Di mana kos tersembunyi
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
