Multilevel Queue Scheduling
IntermediateMultilevel Queue scheduling partitions the ready queue into multiple queues by process type, each with its own algorithm, and Multilevel Feedback Queue allows processes to migrate between queues based on their CPU behavior.
Overview
Real systems have processes with vastly different characteristics: interactive foreground processes need fast response time, while background batch jobs need throughput. Multilevel Queue Scheduling divides the ready queue into separate queues — typically foreground (interactive) and background (batch) — with fixed priority between queues. Foreground processes always run before background ones. Each queue can use its own algorithm (e.g., Round Robin for foreground, FCFS for background). The more powerful Multilevel Feedback Queue (MLFQ) lets processes move between queues based on observed behavior. CPU-bound processes that use their full quantum repeatedly get demoted to lower-priority queues. I/O-bound processes that yield CPU frequently stay in high-priority queues. MLFQ is the foundation of Windows and Linux thread scheduling.
Multilevel Queue: Fixed Partition
In a basic multilevel queue, each process is permanently assigned to a queue at creation. The scheduler services higher-priority queues first. A process in queue 2 (background) only runs when queue 1 (foreground) is empty. This can starve background processes — but for interactive vs batch separation, it is intentional.
// Multilevel Queue — two queue levels
// Queue 0 (highest): Interactive/System processes → Round Robin, quantum=4
// Queue 1 (lowest): Batch processes → FCFS
// Queue assignment rule: interactive tasks go to Queue 0, batch to Queue 1
// Scheduler: always drain Queue 0 before touching Queue 1
Queue<String> queue0 = new LinkedList<>(); // interactive (foreground)
Queue<String> queue1 = new LinkedList<>(); // batch (background)
// Simulate adding processes
queue0.add("UI-Render");
queue0.add("API-Request");
queue1.add("Nightly-Backup");
queue1.add("Log-Compression");
queue0.add("DB-Query"); // interactive arrives — preempts batch
System.out.println("=== Scheduling Order ===");
// Scheduler logic: always pick from queue0 first
while (!queue0.isEmpty() || !queue1.isEmpty()) {
if (!queue0.isEmpty()) {
System.out.println("Running (foreground): " + queue0.poll());
} else {
System.out.println("Running (background): " + queue1.poll());
}
}
// Nightly-Backup and Log-Compression only run after ALL interactive tasks finishMultilevel Feedback Queue: Adaptive Demotion
MLFQ adds dynamic migration: a new process starts at the highest-priority queue (Q0). If it uses its entire quantum without blocking, it is demoted to Q1 (CPU-bound behavior). If it still uses full quanta in Q1, it goes to Q2 (background). If it voluntarily yields (I/O wait), it stays or gets promoted — I/O-bound interactive tasks naturally stay at the top. This separates CPU-bound from I/O-bound processes automatically without configuration.
// MLFQ conceptual diagram:
//
// Q0 (highest, quantum=4ms): [new arrivals, I/O-bound tasks stay here]
// ↓ demote (used full quantum without blocking)
// Q1 (medium, quantum=8ms): [moderately CPU-bound]
// ↓ demote (used full quantum again)
// Q2 (lowest, FCFS): [CPU-intensive batch jobs]
// ↑ promote (after waiting too long — aging)
// Simulating MLFQ process behavior
record MlfqProcess(String name, int remainingBurst, int queueLevel) {}
List<MlfqProcess> processes = new ArrayList<>(List.of(
new MlfqProcess("Browser-Render", 3, 0), // short burst → stays in Q0
new MlfqProcess("Video-Encode", 50, 0), // long burst → gets demoted
new MlfqProcess("Git-Clone", 20, 0) // medium burst → Q1
));
int[] quanta = {4, 8, Integer.MAX_VALUE}; // Q0=4ms, Q1=8ms, Q2=FCFS
for (MlfqProcess p : processes) {
int q = p.queueLevel();
int used = Math.min(p.remainingBurst(), quanta[q]);
boolean usedFullQuantum = (p.remainingBurst() >= quanta[q]);
int newLevel = usedFullQuantum ? Math.min(q + 1, 2) : q; // demote if CPU-bound
System.out.printf("%s: burst=%d, Q%d → used %dms → moved to Q%d%n",
p.name(), p.remainingBurst(), q, used, newLevel);
}Key Points to Remember
- 1Multilevel Queue: processes permanently assigned to fixed-priority queues; higher queues always serviced first.
- 2Multilevel Feedback Queue (MLFQ): processes can move between queues based on CPU usage behavior.
- 3CPU-bound processes that use full quanta are demoted to lower-priority queues.
- 4I/O-bound interactive processes that yield CPU stay in high-priority queues.
- 5Aging in MLFQ promotes long-waiting low-priority processes to prevent starvation.
- 6MLFQ is the conceptual foundation of Windows thread scheduling and Linux CFS.
Interview Questions
Sign in to ask AriaWhat is the difference between Multilevel Queue and Multilevel Feedback Queue scheduling?
How does MLFQ automatically separate CPU-bound from I/O-bound processes?
What happens to a new process when it first enters an MLFQ system?
How does MLFQ handle starvation of processes in the lowest queue?
Ask Aria about Multilevel Queue Scheduling
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.