Your laptop is running dozens of processes right now. Yet your processor core can only execute one instruction stream at a time. Something has to decide who runs and for how long — that something is the CPU scheduler.
Every context switch is free in theory and costly in practice. Swap tasks too often and the CPU wastes time saving and restoring state. Swap too rarely and interactive programs feel sluggish. The scheduler sits in this tension and must resolve it thousands of times per second without ever stopping to think.
Three policies dominate the history of this problem:
- Round-Robin (RR) — every task gets the same fixed time slice in turn. Simple, fair, predictable.
- Multi-Level Feedback Queue (MLFQ) — tasks are sorted into priority queues. New tasks start high; tasks that burn their slice drop lower. Interactive tasks that yield early stay high.
- Completely Fair Scheduler (CFS) — Linux's answer since 2007. Instead of time slices it tracks virtual runtime and always picks the task that has run the least. Fairness emerges from the math, not from bookkeeping.
Each policy optimizes a different thing. Understanding the tradeoff is the key to understanding operating systems.
Comments
Loading comments...