7. CPU scheduling algorithms
One-liner. Every scheduler chooses what to optimize: response, turnaround, throughput or fairness.
Memorize
- FCFS: simple, suffers the convoy effect (short jobs stuck behind long ones).
- SJF / SRTF: optimal average waiting time, needs future knowledge (predict from history).
- Round robin: fairness via quantum; too small = context-switch overhead, too large = FCFS behaviour.
- Priority + aging: prevents starvation by raising waiting tasks' priority.
- MLFQ: multiple queues, demotion on CPU use, promotion on wait — approximates SJF without prediction.
- Lottery/stride: proportional share by tickets/stride.
- CFS used vruntime; EEVDF (Linux 6.6+) uses eligible tasks with virtual deadlines.
- RM/EDF for real-time: EDF is optimal for preemptive uniprocessor scheduling when utilization ≤ 1.
Trap. Choosing SJF in a general-purpose OS — you cannot know the next burst, and long jobs starve. Do this. Pick the metric first (latency vs throughput vs fairness), then the algorithm.
Check
Which scheduling policy minimizes average waiting time when burst times are known?
Why
Running the shortest job first provably minimizes average waiting time, at the cost of starvation and oracle knowledge.