Picture a page that reads “load 12.4 on an 8-core host” while the CPU graph next to it sits at 30%. Both numbers are correct. They’re measuring different things, and the gap between them is usually where the actual problem is.
Load average is one of the oldest numbers on a Unix box, and most of us learned it as “how busy the CPUs are”. On Linux that’s wrong in a specific, useful way.
What goes into the number
The kernel source says it plainly. In kernel/sched/loadavg.c:
The global load average is an exponentially decaying average of nr_running + nr_uninterruptible.
So two kinds of task count:
- Runnable (state
R): on a CPU right now, or ready and waiting in the run queue. - Uninterruptible sleep (state
D): blocked inside the kernel in a way that signals can’t interrupt. In practice that’s mostly waiting on disk I/O, NFS, or certain kernel locks. These tasks use no CPU at all.
The second group is the Linux quirk. On other operating systems, load averages count only CPU demand: threads running or waiting to run. Linux added D tasks in 1993, in a patch from Matthias Urlichs that shipped in Linux 0.99 patchlevel 14. Brendan Gregg’s Linux Load Averages: Solving the Mystery digs up that history, and his summary is that Linux moved from “CPU load averages” to “system load averages”. It measures demand on the whole system, CPU and I/O together.
That’s how you get load 12 at 30% CPU: a handful of runnable tasks plus a pile of tasks stuck waiting on a slow disk.
Three averages, one formula
Every five seconds (LOAD_FREQ is 5*HZ+1 ticks in include/linux/sched/loadavg.h), the kernel counts R + D tasks and folds that count into three running averages. Each one decays at its own rate, stored as fixed-point constants: 1884, 2014 and 2037 out of 2048, for the 1-, 5- and 15-minute averages.
You don’t have to take the smoothing on faith. Here’s the kernel’s arithmetic copied into Python: same constants, same integer maths, and the same rounding that /proc/loadavg applies when it prints. Four tasks become runnable at t=0, stay runnable for five minutes, then everything goes idle:
FSHIFT = 11
FIXED_1 = 1 << FSHIFT # 1.0 in fixed point (2048)
EXP_1, EXP_5, EXP_15 = 1884, 2014, 2037
def calc_load(load, exp, active):
newload = load * exp + active * (FIXED_1 - exp)
if active >= load:
newload += FIXED_1 - 1
return newload // FIXED_1
def fmt(x):
x += FIXED_1 // 200 # the rounding /proc/loadavg adds
return f"{x >> FSHIFT}.{((x & (FIXED_1 - 1)) * 100) >> FSHIFT:02d}"
avg = [0, 0, 0]
for tick in range(1, 121): # one tick every 5 seconds = 10 minutes
active = 4 * FIXED_1 if tick <= 60 else 0
avg = [calc_load(a, e, active) for a, e in zip(avg, (EXP_1, EXP_5, EXP_15))]
t = tick * 5
if t in (60, 300, 360, 600):
print(f"t={t:>3}s load average: {', '.join(fmt(a) for a in avg)}")
t= 60s load average: 2.53, 0.73, 0.25
t=300s load average: 3.98, 2.54, 1.12
t=360s load average: 1.46, 2.08, 1.04
t=600s load average: 0.02, 0.92, 0.80
Two things jump out:
- It lags. A full minute of four busy tasks reads 2.53 on the 1-minute average. That’s 4 × (1 − 1/e): each average gets about 63% of the way to a new steady value per period. The 15-minute average is still at 1.12 after five minutes of saturation.
- It remembers. Five minutes after everything went idle, the 15-minute average still says 0.80. If you alert on it, you’ll get paged late, and the alert will clear late too.
That’s also why the three numbers together tell you a direction. 1.46, 2.08, 1.04 is a spike that’s already fading. 3.98, 2.54, 1.12 is one that’s still building.
Reading /proc/loadavg
uptime and top both read /proc/loadavg. The kernel writes that file with a single format string, in fs/proc/loadavg.c:
seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n",
That gives five fields:
- The three averages, with two decimal places.
running/total: tasks runnable right now (nr_running()) over the total number of threads. This count leaves outDtasks, so it won’t match the load.- The most recently allocated PID.
So is load 12 on 8 cores bad?
It depends on which kind of task makes up the 12. Here’s how I’d split it, in about a minute:
nproc # how many CPUs you're comparing against
vmstat 1 5 # r = runnable, b = blocked waiting for I/O
ps -eo state,pid,comm | awk '$1 ~ /^D/' # who is in uninterruptible sleep
cat /proc/pressure/cpu /proc/pressure/io # PSI, if your kernel has it
rwell abovenproc: work is queueing for CPU. Expect latency to climb. Look at what’s burning CPU, or add capacity.bhigh, CPU mostly idle: tasks are stuck waiting on storage or a network filesystem. More CPU won’t help. Go look at disk latency, a hung NFS mount, or a saturated volume.- Both are low, but the 15-minute average is high: you’re looking at the past. See the “it remembers” point above.
If your kernel has PSI (pressure stall information), it answers the question load average was always being used for. The kernel docs describe /proc/pressure/cpu, io and memory. Each has a some line, the share of time at least some tasks were stalled on that resource, with 10-, 60- and 300-second averages. It’s per resource and it’s a percentage of time, so there’s no core-count arithmetic and no guessing whether the number means CPU or disk.
What to alert on
Load average is fine for a glance at a host. As an alert it’s weak: it lags, it mixes CPU and I/O into one number, and the right threshold changes with core count. Alert on the thing users feel (latency, error rate) and on PSI or run-queue length if you need a saturation signal. Keep load average as context on the dashboard, read alongside nproc.
If this was useful, the same “a high number isn’t a cause” reasoning shows up in percentiles and tail latency and in queueing theory for SREs. Load is a queue length, after all, and queues are where latency comes from.
Comments