Overview
MLFQ (Multi-Level Feedback Queue) is an advanced CPU scheduling algorithm that uses multiple priority queues with different time quantum values. Processes dynamically move between queues based on their behavior, automatically adjusting priorities to balance interactive responsiveness with CPU-intensive throughput.MLFQ is a preemptive algorithm with dynamic priority adjustment. Processes can move between priority levels based on their execution patterns.
How It Works
The MLFQ algorithm follows these steps:- Maintain multiple ready queues, each with a different priority level
- Each queue has its own time quantum (typically increasing at lower priorities)
- New processes start in the highest-priority queue (queue 0)
- Execute processes from the highest-priority non-empty queue
- When a process uses its full quantum without completing:
- Move it to the next lower-priority queue (demotion)
- When a process completes or yields before quantum expires:
- It stays at the current priority (or can be promoted in some variants)
- Always check higher-priority queues before lower ones
MLFQ is also called Multi-Level Feedback Queue Scheduling because processes get feedback based on their behavior and move between levels accordingly.
Algorithm Parameters
| Parameter | Type | Description |
|---|---|---|
llegada | Array | Arrival times for each process |
cpu | Array | CPU burst times (total execution needed) |
quantum | Array | Time quantum for each priority level |
Quantum Array Structure
Thequantum array defines the behavior of each priority level:
- Queue 0: Highest priority, smallest quantum (most responsive)
- Queue N: Lowest priority, largest quantum (most efficient)
Implementation
Here’s the core MLFQ algorithm logic:Example Walkthrough
Let’s simulate MLFQ with quantum = [2, 4]:| Process | Arrival Time | CPU Time |
|---|---|---|
| P0 | 0 | 7 |
| P1 | 1 | 4 |
| P2 | 2 | 1 |
Queue Structure:
- Queue 0: Quantum = 2 (high priority, responsive)
- Queue 1: Quantum = 4 (low priority, efficient)
Execution Timeline:
Step-by-Step:
-
Time 0-2: P0 starts in Q0, quantum=2
- P0 remaining: 7 → 5
- P0 demoted to Q1 (didn’t finish)
- P1 arrives, joins Q0
-
Time 2-4: P1 in Q0, quantum=2
- P1 remaining: 4 → 2
- P1 demoted to Q1
- P2 arrives, joins Q0
-
Time 4-5: P2 in Q0, quantum=2 (completes in 1)
- P2 remaining: 1 → 0 (completes!)
- P2 stays in Q0 (but already done)
-
Time 5-9: Q0 empty, P0 runs in Q1, quantum=4
- P0 remaining: 5 → 1
- P0 stays in Q1 (at lowest level)
-
Time 9-11: P1 in Q1, quantum=4 (completes in 2)
- P1 remaining: 2 → 0 (completes!)
-
Time 11-12: P0 finishes in Q1
- P0 remaining: 1 → 0 (completes!)
Results:
| Process | Start | Finish | Waiting | Turnaround | Path |
|---|---|---|---|---|---|
| P0 | 0 | 12 | 5 | 12 | Q0→Q1→Q1 |
| P1 | 2 | 11 | 5 | 10 | Q0→Q1 |
| P2 | 4 | 5 | 2 | 3 | Q0 |
P2 (shortest process) completed quickly without demotion. P0 and P1 (longer processes) were demoted to lower-priority queues, preventing them from monopolizing the CPU.
Key Characteristics
Advantages
- Automatic priority adjustment - No manual priority assignment needed
- Excellent for mixed workloads - Handles interactive + CPU-intensive
- Responsive to short processes - They stay in high-priority queues
- No starvation - Even low-priority processes eventually run
- Adaptive behavior - Self-optimizing based on process patterns
- Good average response time - Balances fairness and efficiency
Disadvantages
- Complex implementation - More sophisticated than simple algorithms
- Parameter tuning required - Quantum values affect performance
- Higher overhead - Managing multiple queues and level changes
- Can penalize CPU-intensive tasks - They get demoted repeatedly
- Gaming possible - Processes can manipulate the system
Design Principles
MLFQ is built on key principles:Rule 1: Priority Ordering
If Priority(A) > Priority(B), then A runs (B doesn’t)Higher-priority queues are always checked first.
Rule 2: Equal Priority
If Priority(A) = Priority(B), then A and B run in Round RobinWithin each queue, use Round Robin scheduling.
Rule 3: New Arrivals Start High
When a process arrives, place it in the highest-priority queueGive every process a chance to prove it’s short/interactive.
Rule 4: Demotion After Quantum
If a process uses its entire quantum, demote it to the next lower queueCPU-intensive processes move to lower priorities.
Rule 5: Stay if Yielding
If a process yields before quantum expires, it stays at current priorityI/O-bound and interactive processes maintain high priority.
Quantum Configuration Strategies
Exponential Increase
Linear Increase
Adaptive
Preventing Starvation
MLFQ prevents starvation through:Priority Boosting
Better Accounting
Performance Characteristics
- Time Complexity: O(n × levels) per scheduling decision
- Space Complexity: O(n × levels) for queue storage
- Response Time: Excellent for short processes, good for long
- Turnaround Time: Balanced, better than Round Robin
- Throughput: Good for mixed workloads
Real-World Usage
MLFQ is used in many production operating systems:BSD Unix
- 32 priority levels
- Dynamic priority adjustment
- User and kernel priorities
Windows
- 32 priority levels (0-31)
- Real-time priorities (16-31) don’t demote
- Normal priorities (0-15) use MLFQ
Solaris
- 4 scheduling classes
- Time-sharing class uses MLFQ
- Interactive processes get priority boost
Comparison with Other Algorithms
| Metric | RR | Priority | MLFQ |
|---|---|---|---|
| Complexity | Low | Medium | High |
| Adaptivity | None | Static | Dynamic |
| Response Time | Good | Varies | Excellent |
| CPU-Intensive | Fair | Poor | Fair |
| Interactive | Good | Good | Excellent |
| Configuration | 1 param | N params | N params |
Use Cases
MLFQ works best for:
- General-purpose operating systems
- Web servers with mixed request types
- Systems with interactive + batch workloads
- Any scenario requiring automatic priority adjustment
- Multi-user time-sharing systems
Advanced Variants
MLFQ with I/O Priority Boost
MLFQ with User Hints
Fair-Share MLFQ
Try It Out
Use the simulator to experiment with MLFQ:- Try different quantum arrays:
[1,2],[2,4,8],[5,10,15] - Mix short and long processes
- Observe how processes move between queues
- Compare with simple Round Robin
- Test with many levels vs. few levels
Related Algorithms
- Round Robin - MLFQ with single queue
- Priority Scheduling - Static version of MLFQ
- SJF - What MLFQ approximates for unknown burst times