CPU Scheduling

the multilevel feedback queue

/ MLFQ /

Imagine a class where the teacher does not know in advance which students need quick check-ins and which need long stretches of focus, so the teacher watches behavior and adjusts: a student who keeps finishing fast gets short frequent turns; one who needs a long uninterrupted block is moved to a slower track. The multilevel feedback queue does this for processes — it sorts them by their observed behavior and lets them move between queues over time, learning what each one is like.

How it works: there are several queues with decreasing priority, and the higher-priority queues use shorter time quanta. A new process starts in the top queue. If it uses up its whole quantum without blocking (a sign it is CPU-bound), it is demoted to a lower-priority queue with a longer quantum. If it gives up the CPU early to do I/O (a sign it is interactive), it stays high or is promoted. The scheduler serves higher queues first. The net effect is that short, interactive jobs naturally float to the top and get fast response, while long CPU-bound jobs sink to the bottom and run in big efficient chunks when nothing more urgent is ready — without anyone having to predict burst lengths in advance.

Why it matters: this is the most general and most widely influential of the classic schedulers, approximating shortest-job-first using only observed past behavior. To prevent the long jobs at the bottom from starving, real MLFQ designs add aging — periodically boosting everyone back to the top queue. Tuning it is intricate (number of queues, each quantum, demotion and promotion rules), which is its honest downside; but the core idea — adapt a process's priority to how it actually behaves — underlies the schedulers in many real operating systems.

Queue 0 (quantum 8 ms), queue 1 (16 ms), queue 2 (FCFS). A new job enters queue 0; if it runs the full 8 ms without blocking it drops to queue 1; if it again uses its full slice it drops to queue 2. An editor that blocks for keystrokes after 1 ms stays in queue 0 and keeps its snappy response.

MLFQ learns each job's nature from behavior, floating interactive jobs up and sinking CPU-bound ones down.

Without aging, MLFQ can starve the bottom queue, and a process can game it (do brief I/O just before its quantum ends to stay high). Real designs add aging and periodic priority resets to close these gaps.

Also called
MLFQmultilevel feedback queue scheduling多級回饋佇列