Introduction

Interactive systems care about response time: a user who presses a key wants a reaction now, not after a long batch job finishes. Round robin (RR) achieves this by time slicing. Every ready process gets the CPU for at most one time quantum qq, then goes to the back of the queue. Among nn ready processes, no process waits more than (n−1)(n - 1) quanta for its next turn.

Real systems mix interactive and batch work, so they use several ready queues with different policies. A multilevel queue assigns each process permanently to one queue; a multilevel feedback queue (MLFQ) moves processes between queues according to how they behave, so that short and interactive jobs float to the top without the scheduler knowing burst lengths in advance.

The same four-process workload as CPU Scheduling: Criteria, FCFS, SJF, SRTF and Priority is used, so the results can be compared directly.

Prerequisites

Core concepts

Round robin

  • The ready queue is FIFO. The dispatcher takes the head, sets the timer to qq and runs it.
  • If the burst finishes within qq, the process leaves and the next one starts at once.
  • If the timer expires, the process is preempted and appended to the tail.
  • A process never gets more than qq consecutive units while others are ready. (If it is the only ready process, it simply gets another quantum.)

Queue-order convention used in the traces. When a process arrives at the same instant that the running process's quantum expires, the new arrival joins the queue first and the preempted process goes behind it. A stated problem may use the opposite order; follow the problem.

Quantum size.

QuantumBehaviour
qq larger than every burstIdentical to FCFS
qq very smallApproaches processor sharing (each of nn processes runs at speed 1/n1/n); context-switch overhead dominates
Rule of thumbMost CPU bursts (often quoted as about 80%) should finish within one quantum

Waiting bound. With nn processes in the ready queue and switch time ss, the gap between the end of one quantum of a process and the start of its next is at most (n−1)q+ns(n - 1)q + ns: the other n−1n - 1 processes run once each, and there are nn switches (one before each of their runs and one back). With free switching this is the familiar (n−1)q(n - 1)q.

Multilevel queue

The ready queue is split into separate queues, for example system, interactive and batch processes. Each process is placed in one queue for life, and each queue has its own algorithm (RR for interactive, FCFS for batch). Scheduling between queues is either:

  • Fixed priority: a lower queue runs only when all higher queues are empty. A higher-queue arrival preempts a lower-queue process. Lower queues can starve.
  • Time slicing: each queue gets a share of CPU time, for example 80% to the foreground and 20% to the background.

Multilevel feedback queue

Processes move between queues. A typical configuration:

  • Q0: RR with q=2q = 2; Q1: RR with q=4q = 4; Q2: FCFS.
  • Every new process enters Q0.
  • A process that uses its whole quantum is demoted one level (it looks CPU-bound).
  • A process that blocks or finishes before its quantum ends stays at its level.
  • A higher queue has absolute priority. An arrival in Q0 preempts a process running from a lower queue; the preempted process returns to the tail of its own queue with a fresh quantum.
  • Aging: a process that waits too long in a low queue is promoted, which prevents starvation.

An MLFQ is defined by: the number of queues, the algorithm and quantum of each, the demotion rule, the promotion (aging) rule, and the entry queue for new processes. A problem must give these explicitly; the traces use the rules just stated.

Three-level feedback queue with demotion
Figure 1. A three-level feedback queue: Q0 (round robin, q=2q = 2), Q1 (round robin, q=4q = 4) and Q2 (FCFS). New processes enter Q0, a process that uses its full quantum drops one level, and aging moves long-waiting processes up.

Mathematical explanation

Response time bound. In RR with nn ready processes, between two consecutive quanta of one process every other process runs at most once, for at most qq, with one switch ss before each run and one more switch back to the process. So the gap is at most (n−1)q+ns(n - 1)q + ns. Example: n=3n = 3, q=4q = 4, s=1s = 1 gives 8+3=118 + 3 = 11 units.

Overhead. If every quantum is used in full, the useful fraction of CPU time is q/(q+s)q/(q + s). With q=4q = 4 and s=1s = 1, that is 80%, matching the example.

Number of quanta. A burst of length BB needs ⌈B/q⌉\lceil B/q \rceil quanta in RR, so it is preempted ⌈B/q⌉−1\lceil B/q \rceil - 1 times (assuming other processes are always ready).

Worked examples

The workload (from the previous note, priorities not used):

ProcessArrivalBurst
P107
P224
P341
P454

Round robin with q=2q = 2

Trace of the ready queue (head on the left):

TimeEventQueue after the event
0P1 arrives and runs(empty)
2P2 arrives; P1's quantum expires; arrival firstP2, P1
2P2 runsP1
4P3 arrives; P2 expires (2 left)P1, P3, P2
4P1 runsP3, P2
5P4 arrivesP3, P2, P4
6P1 expires (3 left); P3 runsP2, P4, P1
7P3 finishes; P2 runsP4, P1
9P2 finishes; P4 runsP1
11P4 expires (2 left); P1 runsP4
13P1 expires (1 left); P4 runsP1
15P4 finishes; P1 runs(empty)
16P1 finishes

Gantt: P1 0 to 2, P2 2 to 4, P1 4 to 6, P3 6 to 7, P2 7 to 9, P4 9 to 11, P1 11 to 13, P4 13 to 15, P1 15 to 16.

ProcessCTTATWTRT
P1161690
P29730
P37322
P4151064

Average WT =5= 5, average TAT =9= 9, average RT =1.5= 1.5. Compare FCFS: average RT 4.75. Round robin gives up some waiting time to gain response time.

Round robin Gantt chart with quantum 2
Figure 2. Round robin with q=2q = 2 on the four-process workload: nine segments, P3 finishing at 7, P2 at 9, P4 at 15 and P1 at 16.

Effect of the quantum

qqAverage WTContext switches between different processes
15.514
258
377
44.54
74.75 (same schedule as FCFS)3

Average waiting time is not monotonic in qq. It rose from q=2q = 2 to q=3q = 3 and fell again at q=4q = 4. Smaller quanta generally tend to increase switching overhead, but the switch count is not a monotonic law for every workload. Exact counts require the arrivals, bursts, tie rules and switch-counting convention; for the displayed workload and model, use the counts in the table.

Adding switch cost

If each of the 8 switches at q=2q = 2 costs 1 unit, the last process finishes at 16+8=2416 + 8 = 24 and CPU utilization falls to 16/24=2/316/24 = 2/3. With q=4q = 4 the same cost gives 16+4=2016 + 4 = 20 and utilization 16/20=80%16/20 = 80\%.

Quantum edge cases

Arrival at the instant a quantum expires. P1 (arrival 0, burst 4), P2 (1, 3), P3 (2, 2), q=2q = 2. At time 2, P1's quantum expires and P3 arrives.

Rule at time 2Gantt chartCT of P1, P2, P3WT of P1, P2, P3
New arrival first (the convention used in the traces)P1 0 to 2, P2 2 to 4, P3 4 to 6, P1 6 to 8, P2 8 to 98, 9, 64, 5, 2
Preempted process firstP1 0 to 2, P2 2 to 4, P1 4 to 6, P3 6 to 8, P2 8 to 96, 9, 82, 5, 4

Both give an average WT of 11/311/3, but individual completion times differ, so a question that asks about one process depends on the rule. P2 arrived at 1, before the quantum expired, so it is ahead of both under either rule.

A burst that ends exactly at the quantum. In the chart above, P1's second run uses its remaining 2 units, exactly one quantum. The process terminates; it is not put back in the queue, and no extra switch is counted for it.

A lone process. If only one process is ready when its quantum expires, it continues; whether that counts as a context switch is a convention. Only switches between different processes are counted, so a lone process that continues is not a switch, since no other process's state is loaded; read the question's rule.

Largest quantum for a response limit. Five processes are always ready, s=1s = 1, and each process must wait at most 30 units between the end of one of its quanta and the start of its next. The bound (n−1)q+ns(n - 1)q + ns gives 4q+5≤304q + 5 \le 30, so q≤6.25q \le 6.25 and the largest integer quantum is 6, with a gap of exactly 29. A simulation with q=6q = 6 and q=7q = 7 measures gaps of 29 and 33.

A multilevel feedback queue trace

Q0 (RR, q=2q = 2), Q1 (RR, q=4q = 4), Q2 (FCFS), with the rules above. Jobs: A (arrival 0, burst 9), B (1, 3), C (2, 1).

  • 0 to 2: A runs in Q0 and uses its full quantum: demoted to Q1. At 2, C arrives into Q0 behind B.
  • 2 to 4: B runs in Q0, full quantum, 1 left: demoted to Q1 (behind A).
  • 4 to 5: C runs in Q0 and finishes.
  • 5 to 9: A runs in Q1 for its full quantum of 4, 3 left: demoted to Q2.
  • 9 to 10: B runs in Q1 and finishes.
  • 10 to 13: A runs in Q2 (FCFS) and finishes.

Completion: A 13, B 10, C 5. Waiting: A 4, B 6, C 2. The short job C finishes first even though it arrived last, without the scheduler knowing any burst length.

Preemption across levels. Change C to arrive at 6 with burst 2. Then A runs 0 to 2 (to Q1), B 2 to 4 (to Q1), and A starts its Q1 quantum at 4. At 6, C arrives in Q0 and preempts A, which goes back to the tail of Q1 with 5 units left. C runs 6 to 8, B finishes 8 to 9, and A runs 9 to 13 in a fresh Q1 quantum. It uses all 4 units with 1 still left, so it is demoted to Q2 and finishes there, 13 to 14.

Important properties and observations

  • RR never starves a process; FCFS order is preserved within the queue.
  • RR is preemptive by construction, even when no new process arrives.
  • Average turnaround of RR is often worse than SJF; its advantage is response time and fairness.
  • Fixed-priority multilevel queues can starve the low queues; MLFQ uses aging to prevent that.
  • MLFQ approximates SJF: short and I/O-bound jobs stay in the top queues, CPU-bound jobs sink.

Common misconceptions.

  • "A smaller quantum always reduces waiting time." The table above shows otherwise, and overhead grows.
  • "In RR a finishing process wastes the rest of its quantum." The next process starts immediately.
  • "Multilevel queue and multilevel feedback queue are the same." Only the feedback version moves processes between queues.

GATE examination perspective

  • RR traces. Write the queue after every event and apply the arrival-before-preempted rule (or the stated rule). Queue order at a simultaneous arrival is the step that needs most care.
  • Quantum extremes. q≥q \ge the largest burst gives FCFS; tiny qq gives high overhead.
  • Counting context switches. Count changes of running process; read whether the first dispatch and switches to idle are counted.
  • Response time questions. RR bounds the gap between turns by (n−1)q+ns(n - 1)q + ns (count the switches carefully); the largest qq that keeps response under a given limit follows from that bound.
  • MLFQ. Track each job's level and remaining time; apply demotion only when the full quantum is used; check whether higher-level arrivals preempt.
  • Starvation. Fixed-priority multilevel queues starve; RR and MLFQ with aging do not.

Summary

Sources

  1. A. Silberschatz, P. B. Galvin, G. Gagne, Operating System Concepts, 10th ed., Wiley: Chapter 5, Section 5.3 Scheduling Algorithms (round robin, multilevel queue, multilevel feedback queue).
  2. A. S. Tanenbaum, H. Bos, Modern Operating Systems, 4th ed., Pearson: Section 2.4.3 Scheduling in Interactive Systems (round robin, priority scheduling, multiple queues).

Next steps