Smarter scheduling
Priorities
A scheduler can give each job a priority. The ready job with the highest priority runs first. Jobs with the same priority take turns, round robin. A waiting job doesn't need the CPU, so lower jobs run meanwhile.
Multi-level feedback queue
A multi-level feedback queue (MLFQ) keeps queues from high priority to low and runs the highest queue that isn't empty. The OS rarely knows which jobs are quick, so MLFQ watches them. A new job starts at the top. A job that uses its whole time slice moves down a queue. A job that stops early to wait, like for a key press, stays where it is.
Starvation and boosts
If short jobs keep the top queues busy, a long job at the bottom may never run. That is starvation. The fix is a priority boost: every so often, MLFQ moves every job back to the top. The long job gets a turn, and a job that became interactive moves back up.
Choosing a time slice
Every context switch costs time with no useful work. Short slices feel quick but waste more time switching. Long slices waste less but each job waits longer. If a switch costs 1 ms, 10 ms slices lose about 9% of the CPU, and 100 ms slices about 1%. MLFQ mixes both: short slices in the top queues, long slices at the bottom.
Many cores
Each core has a cache of data it used lately. Running a job on the same core again reuses that warm cache: cache affinity. But no core should sit idle, so the OS balances the load and sometimes moves a job.
Remember
- Higher priority runs first; equal priority takes turns.
- MLFQ: use the whole slice, move down; stop early, stay up.
- A boost lifts every job to the top, so nothing starves.
- Short slices feel quick; long slices waste less.
- Keep jobs on their core, but keep cores busy.