Round-robin scheduling

On this page 7

Round-robin scheduling is a preemptive CPU scheduling algorithm that gives every ready process or thread a fixed time slice, called a quantum, in strict rotation. When the quantum expires, the running task is moved to the back of the ready queue and the next one runs. In operating systems, it is the classic method for time-sharing, because it guarantees that no runnable task waits indefinitely.

The algorithm is simple, fair in CPU share and predictable in its worst-case waiting time. Its behavior depends almost entirely on one parameter, the length of the time quantum, which trades responsiveness against the overhead of context switches.

How round-robin scheduling works

The scheduler keeps runnable tasks in a first-in, first-out ready queue. It dispatches the task at the head and arms a timer interrupt for one quantum. Three outcomes are possible: the task finishes, it blocks on I/O and leaves the queue voluntarily, or the timer fires and the kernel preempts it.

On preemption, the kernel saves the task state in its process control block, appends the task to the tail of the queue and loads the next one. A task that wakes from I/O is also appended to the tail. With n ready tasks and quantum q, no task waits longer than (n − 1) × q before it runs again, ignoring switch overhead.

The table below traces three processes, all arriving at time 0, under a quantum of 4 ms.

ProcessCPU burstExecution intervalsCompletion time
P110 ms0-4, 12-16, 19-2121 ms
P24 ms4-88 ms
P37 ms8-12, 16-1919 ms
Round-robin trace with a 4 ms quantum

The average turnaround time here is 16 ms. Shortest job first would finish the same workload with an average of about 12.3 ms, which illustrates the main cost of round robin: fairness rather than minimal turnaround.

Choosing the time quantum

The quantum length decides whether round robin behaves well. A very long quantum turns it into first-come, first-served scheduling, with poor responsiveness. A very short quantum makes the system spend a large share of time switching, because each context switch costs register saving, scheduler work and, more importantly, cache and TLB disruption.

A widely used rule of thumb is that the quantum should be longer than about 80 percent of CPU bursts, so most interactive tasks finish or block within one slice. General-purpose systems typically use quanta in the range of a few milliseconds to around 100 ms, while a context switch itself costs on the order of microseconds.

The following table shows how the quantum shapes behavior.

Quantum lengthResponsivenessSwitch overheadResulting behavior
Very short (under 1 ms)ExcellentVery highThroughput loss, cache thrashing
Moderate (5-50 ms)GoodLowBalanced time-sharing
Long (100 ms or more)SluggishVery lowApproaches FIFO behavior
UnboundedPoorMinimalIdentical to first-come, first-served
Effect of quantum length

Comparison with other scheduling algorithms

Round robin occupies a middle position among the classic CPU scheduling policies. It is preemptive, unlike first-come, first-served, and it needs no knowledge of burst lengths, unlike shortest job first. It also ignores priorities, which separates it from priority scheduling.

The comparison below summarizes the main differences.

AlgorithmPreemptiveNeeds burst estimatesMain strengthMain weakness
Round robinYesNoFair, bounded waitingHigher average turnaround
First-come, first-servedNoNoMinimal overheadConvoy effect
Shortest job firstOptionalYesOptimal average waitingStarvation of long jobs
Priority schedulingOptionalNoExpresses importanceStarvation without aging
Multilevel feedback queueYesNo, learns behaviorFavors interactive tasksComplex tuning
Round robin and related algorithms

Round robin inside real operating systems

Pure round robin is rarely used alone in modern kernels, but it appears as a building block. In a multilevel feedback queue, each priority level is often served round robin, with shorter quanta at higher levels. Classic Unix schedulers and the Windows dispatcher rotate threads of equal priority in round-robin fashion.

POSIX defines an explicit SCHED_RR real-time policy, available on Linux, in which threads of the same static priority share the CPU in rotation, while SCHED_FIFO threads run until they block or yield. Linux normal tasks, by contrast, use a fair scheduler based on virtual runtime rather than fixed slices, which achieves round-robin-like fairness with weighted shares.

  • Weighted round robin gives some tasks several slices per cycle.
  • Deficit round robin carries unused credit forward, common in network packet scheduling.
  • Virtual round robin gives I/O-bound tasks priority after they wake up.

Limitations and common misconceptions

Round robin treats CPU-bound and I/O-bound processes alike, which in practice penalizes I/O-bound tasks: they block early, give up the rest of their slice and then wait behind CPU-bound tasks that use their full quantum. This is why many systems add priority boosts or feedback queues on top.

The table lists frequent misunderstandings and the accurate view.

MisconceptionAccurate viewConsequence
Shorter quantum is always betterOverhead and cache misses growLower throughput
Round robin minimizes waitingIt bounds waiting, not averageLonger turnaround than SJF
All tasks get equal serviceBlocking tasks forfeit slice timeI/O-bound tasks lose CPU share
It suits hard real-time workNo deadline awarenessUse EDF or fixed priorities
Misconceptions about round robin

A further subtlety is that a context switch costs more than its direct time: refilling caches after a switch can dominate on modern processors, so measured overhead often exceeds the nominal switch cost.

Put simply

Round-robin scheduling is like taking turns on a single computer in a classroom. Each student gets the same few minutes, then moves to the end of the line, and the next student sits down. Nobody keeps the computer forever, and nobody waits forever.

The length of each turn is the key choice. Very short turns waste time on swapping seats, while very long turns make everyone else wait too much.

In practice

A small embedded controller in an industrial machine runs four tasks of equal importance: reading sensors, updating a display, logging data and handling a serial link. The developers configure a real-time kernel with round-robin scheduling and a 10 ms quantum for these tasks at the same priority.

Each task gets the processor at least once every 30 ms of waiting, which keeps the display smooth and the serial link responsive. When the logging task was later found to block frequently on flash writes, it simply gave up its slice early without slowing the others. The outcome was predictable, bounded latency for every task without the complexity of tuning individual priorities, and the team reserved a higher fixed priority only for the emergency stop handler.