CPU Scheduler
The part of the kernel that decides which runnable thread gets each CPU core next, and for how long, trading throughput against latency.
The CPU scheduler is the part of the operating system kernel that decides which runnable thread runs on each core next and for how long. A machine typically has far more runnable threads than cores, so the scheduler is constantly choosing, and its policy decides whether the machine feels responsive under load or merely stays busy.
The core tension is throughput versus latency. Long time slices and few switches maximize total work, because every context switch costs cache warmth and bookkeeping. Short slices and eager preemption minimize how long an interactive thread waits after it becomes runnable, such as one woken by a keypress, a network packet, or a display refresh. No single policy wins both. Different workloads want different points on the curve: a build server wants throughput, while a game or an audio pipeline wants every frame's thread to run now, since a slow frame is a visible stutter (see Frame Pacing).
Linux's history shows how the trade-offs have moved:
- CFS (Completely Fair Scheduler, 2007) tracked each thread's accumulated runtime and always ran the one that had had the least, weighted by its
nicevalue. It was fair, but latency-sensitive work needed heuristics on top. - EEVDF (2023) replaced it with virtual deadlines, so a thread that sleeps often and runs briefly gets scheduled sooner without special cases.
- sched_ext (2024) lets a scheduler be loaded at runtime as an eBPF program. That made scheduling policy something users can swap per workload, for example a scheduler that prioritizes threads on the critical path of frame delivery while gaming, without rebuilding the kernel.
Scheduling also interacts with everything around it. cgroup CPU weights decide how groups share time before the scheduler picks threads within a group. CPU Affinity restricts which cores a thread may use. A priority inversion, where a high-priority thread waits on a lock held by a low-priority one that never gets scheduled, can defeat any policy and is a classic source of heisenbugs.
The general principle is the one behind every Event Loop: whoever holds the processor decides how responsive everything else is, and a fair share is not always the right one.
See also4
Futex
The Linux primitive that makes locks cheap by handling the uncontended case entirely in user space and asking the kernel for help only when a thread actually has to wait, the foundation under most thread libraries.
Systems & Tooling8 connections
Pressure Stall Information
A kernel metric for how much time work spent waiting on CPU, memory, or I/O, which measures contention directly where utilization figures only hint at it.
Systems & Tooling13 connections
Dynamic Voltage and Frequency Scaling
Adjusting a processor's voltage and clock speed on the fly to match the work, exploiting the fact that power rises with the square of voltage.
Systems & Tooling9 connections
Hybrid CPU Architecture
Processors that mix large fast cores with small efficient ones on one chip, first in phones and now in laptops and desktops, which saves power and adds throughput but hands the operating system a hard scheduling problem.
Systems & Tooling5 connections
Linked from13
- BenchmarkingTesting & Verification
Measuring how fast code runs under controlled conditions, which is far harder to do honestly than it looks.
- CPU AffinitySystems & Tooling
Restricting which cores a thread may run on, which matters most on processors whose cores are not all alike.
- DeadlockComputation & Algorithms
When two or more processes each wait for something another holds, so none can ever proceed, and the four conditions that must all be true for it to happen.
- Dynamic Voltage and Frequency ScalingSystems & Tooling
Adjusting a processor's voltage and clock speed on the fly to match the work, exploiting the fact that power rises with the square of voltage.
- Frame PacingGraphics & Rendering
How evenly frames are delivered over time, which shapes perceived smoothness more than average frame rate does.
- FutexSystems & Tooling
The Linux primitive that makes locks cheap by handling the uncontended case entirely in user space and asking the kernel for help only when a thread actually has to wait, the foundation under most thread libraries.
- Hybrid CPU ArchitectureSystems & Tooling
Processors that mix large fast cores with small efficient ones on one chip, first in phones and now in laptops and desktops, which saves power and adds throughput but hands the operating system a hard scheduling problem.
- KernelSystems & Tooling
The core of an operating system that runs with full hardware privileges, managing processes, memory, devices, and files on behalf of every other program.
- Load AverageSystems & Tooling
The three numbers in uptime and top, what Linux actually counts in them, and why they are a rough smoke alarm rather than a measure of how busy a machine is.
- Pressure Stall InformationSystems & Tooling
A kernel metric for how much time work spent waiting on CPU, memory, or I/O, which measures contention directly where utilization figures only hint at it.
- Resource StarvationTesting & Verification
Failures caused by competition for a finite shared resource rather than by any defect.
- Sound ServerSystems & Tooling
The background service that sits between applications and audio hardware, mixing many programs' sound together, routing it to the right speakers or headphones, and handling volume, device switching and latency.
- Thread PoolSystems & Tooling
A fixed set of threads kept alive to run many short tasks from a queue, avoiding the cost of creating a thread per task and capping concurrency, with sizing rules and failure modes that shape how servers and runtimes behave under load.