Multilevel feedback queue

Also known as: MLFQ

On this page 7

A multilevel feedback queue (MLFQ) is a CPU scheduling algorithm that keeps several ready queues of different priority and moves each process between them according to its observed behavior. In operating systems, it is the classic answer to a hard problem in processes & scheduling: giving interactive tasks fast response while still letting long CPU-bound jobs finish efficiently, without knowing in advance how long any job will run.

The key idea is learning from history. A process that uses its entire time slice is treated as CPU-bound and is demoted to a lower queue; a process that blocks early for input or output stays near the top. Periodic priority boosts prevent starvation. Variants of this design have shaped the schedulers of Unix, BSD, Solaris and Windows for decades.

How a multilevel feedback queue schedules processes

An MLFQ scheduler always runs the highest-priority non-empty queue first and applies round-robin scheduling among the processes inside that queue. Lower queues run only when every queue above them is empty, so priority is strict between levels and fair within a level.

The feedback comes from a small set of movement rules. A new process enters at the top priority level, because the scheduler assumes it might be short or interactive. If the process consumes its full time allotment at a level, the scheduler concludes that it is CPU-bound and moves it down one level. If it gives up the CPU before the allotment expires, it keeps its level.

The following table summarizes the standard rule set that most textbook and production variants share in some form.

RuleConditionScheduler action
Priority orderTwo processes in different queuesRun the one in the higher queue
Equal priorityTwo processes in the same queueAlternate in round-robin order
EntryA new process arrivesPlace it in the top queue
DemotionProcess uses its full allotment at a levelMove it one level down
Priority boostA fixed period S elapsesMove all processes to the top queue
Core rules of a multilevel feedback queue

Because a running process at a low level can be preempted the moment a higher queue becomes non-empty, an interactive process that wakes up after a keystroke usually gets the CPU within one short quantum.

Queue levels, time slices and tuning parameters

An MLFQ is defined by its tuning parameters, and the quality of the scheduler depends heavily on choosing them well. Typical designs give short quanta to high queues and progressively longer quanta to low queues, because high queues hold interactive work that needs quick turns while low queues hold batch work that benefits from fewer context switches.

The table below lists the main parameters, a representative range and the behavior each one controls. Exact values differ widely between implementations.

ParameterTypical rangeWhat it controls
Number of queues3 to 64 levelsGranularity of priority distinctions
Top-level quantumAbout 5 to 20 msResponsiveness of interactive tasks
Bottom-level quantumAbout 50 to 200 msThroughput and context-switch overhead
Allotment per levelOne to several quantaHow quickly CPU-bound work sinks
Boost period SAbout 0.1 to 1 sStarvation bound and adaptivity
Main MLFQ tuning parameters

The boost period is the most delicate value. If it is too long, long-running jobs can starve behind a stream of interactive tasks; if it is too short, CPU-bound jobs return to the top too often and degrade interactive latency. Many designers call such values voodoo constants, because they are set empirically rather than derived.

A multilevel feedback queue combines ideas from several simpler algorithms. It approximates shortest job first without needing job lengths, borrows round-robin scheduling within each level, and uses a form of aging to avoid the starvation that plain priority scheduling suffers from.

AlgorithmNeeds job lengthStarvation riskInteractive response
First-come, first-servedNoNone, but long waitsPoor
Shortest job firstYesHigh for long jobsGood if lengths known
Round-robin schedulingNoNoneModerate
Static priority schedulingNoHigh without agingGood for high priority
Multilevel feedback queueNo, learns itLow with boostsGood
MLFQ and neighboring algorithms

A plain multilevel queue without feedback differs in one decisive way: processes are permanently assigned to a queue, such as system, interactive or batch, and never move. The feedback mechanism is what turns a static classification into an adaptive scheduler.

Gaming, starvation and accounting fixes

Naive MLFQ rules contain two well-known weaknesses. The first is starvation: with many interactive processes, low queues may never run. The periodic priority boost solves this by guaranteeing that every process eventually returns to the top and receives some CPU time.

The second weakness is gaming the scheduler. If demotion happens only when a process uses a whole quantum in one go, a program can issue a trivial I/O request just before the quantum ends and stay at high priority forever. Modern variants fix this with cumulative CPU accounting: the scheduler tracks total time used at a level, regardless of how many times the process yielded, and demotes it once the allotment is spent.

  • Behavior changes are handled by boosts, so a batch job that becomes interactive regains high priority.
  • Priority inversion can still occur when a low-level process holds a lock that a high-level process needs.
  • User hints, such as the Unix nice value, often shift a process’s base level or decay rate.

Multilevel feedback queues in real operating systems

Production schedulers rarely implement the textbook MLFQ exactly, but many inherit its structure. The following table shows how several well-known systems apply the same feedback principle.

SystemApproachFeedback signal
Traditional BSD UnixPriority recomputed from decayed CPU usageRecent CPU time and nice value
Solaris time-sharing class60 levels with a dispatch tableQuantum expiry and sleep return
Windows NT family32 levels with dynamic boostsI/O completion and foreground focus
Linux CFS and EEVDFNot MLFQ; virtual runtime orderingAccumulated weighted runtime
MLFQ-style designs in practice

The Linux example is a useful contrast. Its fair schedulers achieve interactive responsiveness through proportional sharing rather than discrete queues, which shows that MLFQ is one solution among several, not the only modern approach.

In simple terms

Think of a busy help desk with several lines. Every new visitor starts in the fast line. If a visitor asks a quick question, they leave quickly. If a visitor needs a long conversation, the clerk moves them to a slower line for longer sessions.

The fast lines are always served first. Every so often, the clerk moves everyone back to the front, so nobody waits forever. In this way, the computer keeps quick tasks snappy and still finishes the long ones.

A practical example

A developer works on a laptop while a video export runs in the background. The text editor wakes up for each keystroke, runs for under a millisecond and then waits again. It never exhausts its allotment, so it stays in the top queue and responds within a few milliseconds.

The video encoder, by contrast, uses every quantum it receives. After a few slices it sinks to the lowest level, where it runs in longer 100 ms quanta whenever the editor and other interactive programs are idle. Each second, a priority boost lifts it briefly to the top, which guarantees progress even during heavy typing. The outcome is a responsive editor and a steadily advancing export, without the user setting any priorities by hand.