A run queue, also called a ready queue, is the kernel data structure that holds every thread or process that is ready to execute but not currently running on a processor. In the field of Processes & scheduling within operating systems, the run queue is the pool from which the CPU scheduler selects the next task whenever a core becomes free, a time slice expires or a higher-priority task wakes up.
The run queue is distinct from wait queues, which hold tasks blocked on I/O, locks or timers. A task moves into the run queue when it becomes runnable and leaves it when it is dispatched or blocks again. The length of the run queue is therefore a direct measure of CPU contention, and it feeds the familiar load average reported by Unix-like systems.
How the run queue fits into the process life cycle
The run queue holds tasks in the ready state of the process state model. A newly created task, a task whose I/O has completed or a preempted task is enqueued; the dispatcher dequeues one task and performs a context switch to it. When the running task blocks, it moves to a wait queue instead.
The following table shows how common state transitions change the run queue.
| Event | Transition | Run queue effect |
|---|---|---|
| Process creation | New to ready | Task is enqueued |
| Dispatch | Ready to running | Task is dequeued |
| Time slice expiry | Running to ready | Task is enqueued again |
| I/O request or lock wait | Running to blocked | No entry; task joins a wait queue |
| I/O completion or wakeup | Blocked to ready | Task is enqueued |
| Exit | Running to terminated | No entry |
Whether the currently running task is counted as part of the run queue depends on the kernel. Linux counts the running task in its per-CPU run queue statistics, while many textbook models describe the ready queue as containing only waiting tasks. This difference matters when interpreting monitoring figures.
Run queue data structures in real kernels
A run queue is rarely a simple first-in, first-out list. Its structure follows the scheduling policy: round-robin scheduling suits a circular FIFO, priority scheduling needs one list per priority level, and fair-share schedulers need an ordered structure keyed by consumed CPU time.
The table below compares structures used by well-known schedulers.
| Structure | Used by | Pick-next cost | Strength |
|---|---|---|---|
| FIFO list | Simple round-robin, FCFS | O(1) | Minimal overhead |
| Priority array with bitmap | Linux O(1) scheduler, Windows dispatcher | O(1) | Fast lookup of highest priority |
| Red-black tree | Linux CFS | O(log n) insert, cached leftmost pick | Fair ordering by virtual runtime |
| Augmented tree by deadline | Linux EEVDF, SCHED_DEADLINE | O(log n) | Latency and deadline awareness |
| Multilevel queues | Multilevel feedback queue designs | O(1) per level | Separates interactive and batch work |
Windows keeps 32 priority levels in its dispatcher database with a bitmask that marks non-empty levels, so finding the highest-priority ready thread is a single bit scan. Linux replaced its O(1) scheduler with the Completely Fair Scheduler in 2007 and moved to EEVDF in kernel 6.6, but both keep tasks in a tree ordered by a fairness key.
Per-CPU run queues and load balancing
Modern multiprocessor kernels use one run queue per logical CPU rather than a single global queue. A global queue protected by one lock becomes a scalability bottleneck as core counts grow, and it destroys cache affinity because a task may resume on a different core every time.
Per-CPU queues introduce a new problem: one core may be overloaded while another is idle. Kernels solve this with load balancing, which periodically migrates tasks between queues, and with work stealing, where an idle core pulls a task from a busy neighbor. Linux organizes this through scheduling domains that mirror the hardware topology, balancing more often between SMT siblings than across NUMA nodes.
The table summarizes the trade-off between global and per-CPU designs.
| Property | Single global queue | Per-CPU queues |
|---|---|---|
| Lock contention | High on many cores | Low, mostly local |
| Cache affinity | Poor | Good |
| Load distribution | Automatic | Requires active balancing |
| Typical use | Early SMP kernels, simple RTOS | Linux, Windows, FreeBSD ULE |
Measuring run queue length
Run queue length is one of the most useful indicators of CPU saturation. As a rule of thumb, a sustained number of runnable tasks above the number of logical CPUs means work is waiting for processor time, which raises latency even when utilization looks acceptable.
Administrators read it through several tools, listed below.
| Tool or metric | Platform | What it reports |
|---|---|---|
| vmstat r column | Linux, BSD | Runnable tasks at sample time |
| Load average | Unix-like systems | Exponentially damped average over 1, 5 and 15 minutes |
| /proc/schedstat | Linux | Per-CPU run and wait time |
| Processor Queue Length | Windows Performance Monitor | Ready threads waiting for any processor |
| sar -q | Linux, Solaris | Historical queue size and load |
Interpretation requires care. Linux load average also includes tasks in uninterruptible sleep, usually waiting for disk or network storage, so a high load with idle CPUs points to an I/O problem rather than CPU contention.
Common problems and misconceptions
- Starvation: in strict priority queues, low-priority tasks may never be dequeued; aging raises their priority over time.
- Priority inversion: a high-priority task waits on a lock held by a low-priority task that cannot run; priority inheritance shortens the inversion.
- Lock contention: a single shared queue limits throughput on systems with dozens of cores.
- Misreading load average: a value of 8 is saturation on four cores but light load on 64 cores.
- Imbalance: aggressive affinity pinning can leave some per-CPU queues long and others empty.
A plain-language summary
A computer has only a few processors, but it runs hundreds of programs. Most of them are waiting most of the time. The run queue is the waiting line for programs that are ready to work right now.
Think of a bank with a few tellers. Customers who are ready to be served stand in line. Customers who still fill out forms sit elsewhere. The operating system calls the next customer from the line each time a teller is free. A long line means the processors are too busy.
An example from practice
A web team runs an API on a virtual machine with 8 virtual CPUs. Users report slow responses at peak hours, yet the dashboard shows CPU utilization of only about 85 percent. An engineer runs vmstat and sees the r column between 20 and 30, far above the eight available CPUs.
The long run queue shows that request threads wait for processor time even though utilization never reaches 100 percent. The team reduces the worker pool from 64 to 16 threads and adds two more instances behind the load balancer. After the change, the run queue stays below 8 and the 95th percentile response time drops from about 900 ms to under 200 ms.