Skip to content

Lesson 6 of 13 · 14m

Stolen CPUs and Throttled Containers

`nr_throttled` in cpu.stat and `%st` steal time are CPU you're paying for and not getting.

Two mechanisms take CPU you think you own. On a VM, the hypervisor may give your vCPU's slot to another tenant; Linux reports the lost time as %st — steal — in top and vmstat, and your process simply runs less. In a container, the kernel does not steal anything; it enforces. cgroup v2 cpu.max is a quota written as <max> <period> — 50000 100000 means 50 ms of CPU per 100 ms window — and when the quota is gone the threads do not slow down. They sleep until the next window.

Reading throttling

The counters live in /sys/fs/cgroup/cpu.stat: nr_periods, nr_throttled, throttled_usec. A workload showing half a second of wall latency per request with nr_throttled in the thousands is not slow code; it is a quota. The trap is that throttling is bursty — average CPU looks low while every request hits the wall mid-flight. top on the host will not show it; the guest's own stats do.

Older kernels made this worse for a different reason: a CFS bandwidth accounting bug let runtime drift between per-CPU buckets, so Kubernetes CPU limits could throttle a workload that had not spent its quota. The fixes landed around kernel 4.18, but the incident reports it generated remain the best documentation of how quota throttling behaves. It is also why the "always set CPU limits" cargo cult got questioned — requests guarantee scheduling share, while limits guarantee throttle windows, and the throttle is usually worse than the contention it was meant to prevent. Requests map to cpu.weight shares; only limits produce the hard stop.

Steal time is not yours to fix in code

%st in top and st in vmstat mean the hypervisor scheduled your vCPU elsewhere. No code change recovers it. The answers are a different instance class, dedicated hosts, or a less oversold provider. Steal during your own peak window is capacity theft; steal only during provider maintenance windows is noise. Persistent double-digit steal is a move-the-workload conversation, not an optimization target.

SMT is the quieter version of the same idea: your "second core" is a hardware thread sharing execution ports with its sibling, so the last fraction of a hyperthreaded box is never worth a full core.

Pressure tells the same story faster

Kernel 4.20 added PSI — pressure stall information — under /proc/pressure/ for cpu, memory, and io. The some line counts time at least one task stalled on the resource; full counts time every non-idle task stalled. avg10 on cpu full climbing past a few percent is the host-level version of nr_throttled: contention you can read without knowing the cgroup layout. cat /proc/pressure/cpu is a two-second check before any deeper profiling. Containers expose their own cpu.pressure file under /sys/fs/cgroup/ alongside cpu.stat, so the stall view works per workload, not just per host.

Evidence

Postmortems from the Kubernetes era repeat one shape: a service with p99 spikes, CPU graphs at 30%, and nr_throttled climbing with each spike. Dropping the limit while keeping the request fixed the latency more often than any code diff — the quota was the bottleneck, not the work. On the VM side, st climbing while %us stays flat is how you learn your "dedicated" host isn't.

The practice

  • Read /sys/fs/cgroup/cpu.stat nr_throttled and throttled_usec before profiling anything in a container.
  • Check st in vmstat on VMs; persistent steal is a provider problem, not a software one.
  • Treat cpu.max / limits.cpu as a latency hazard — prefer requests for guaranteed share; reserve limits for hard ceilings that genuinely require them.
  • Budget SMT honestly: a "4-vCPU" cloud box is often two physical cores.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.