Noisy Neighbors in Virtualization: What CPU Steal and PSI Really Show
8% CPU steal on one vCPU means 0.8 seconds out of every ten when your code was ready to run while the physical processor was busy with something else. A background job won't notice. But for an API with a 50 ms response budget, one such pause at the wrong moment turns into a long p99 tail.
With virtualization, contention for resources happens in two places. The first is the host. The virtual processor is ready to run, but the hypervisor has not yet given it a physical core, and the guest sees that wait as steal. The second is the VM itself. There are more runnable tasks than free vCPUs, and they queue in the guest kernel's scheduler. PSI shows that queue.
These two queues get confused all the time. High steal with zero PSI looks odd, but it is a normal picture when only one thread runs on the vCPU: it has nobody to queue behind inside the guest, it simply freezes together with its vCPU. And the other way round, PSI can be high with zero steal when the application hits its container quota on an almost empty VPS.
It usually starts the same way: one replica responds slower than the rest, load average is calm, and the machine's CPU graph is flat. Looking at only one metric makes it easy to treat the wrong problem: order a bigger plan when your own quota is to blame, or spend a week optimizing code when the host CPU is busy with a neighbor.
Where steal time comes from
In KVM, every vCPU runs as an ordinary thread on the host. When the guest needs to execute code, that thread joins the host scheduler's queue and waits for a free logical processor. If the processor is busy with another VM, another vCPU of the same machine or a host process, the waiting time accumulates in the steal counter.
The hypervisor maintains the counter and passes it to the guest through a shared memory area; on x86 the mechanism is MSR_KVM_STEAL_TIME. Time is counted in nanoseconds, and the guest kernel adds it to /proc/stat: steal is the eighth number in each CPU's line. Time when the vCPU itself has nothing to do does not count. Idle is not theft.
In top this is the st field. Individual vCPUs are easier to watch with mpstat from the sysstat package: the command below takes ten samples one second apart, for each vCPU plus an overall all line.
date -u +%FT%TZ uname -r LC_ALL=C mpstat -P ALL 1 10 The value in /proc/stat accumulates since boot, and even on a calm machine it can show a large number left over from old spikes. What matters is the increase. The percentage for one vCPU is the steal increase divided by the sum of increases of the first eight fields. The guest and guest_nice fields are already included in user and nice, so they are not added to the denominator, otherwise the percentage comes out too low.
# steal of one vCPU over 10 seconds from /proc/stat cpu=cpu0 a=($(grep "^$cpu " /proc/stat)); sleep 10; b=($(grep "^$cpu " /proc/stat)) # fields 1-8: user nice system idle iowait irq softirq steal awk -v a="${a[*]}" -v b="${b[*]}" 'BEGIN { split(a, x); split(b, y) for (i = 2; i <= 9; i++) total += y[i] - x[i] printf "%s steal: %.2f%%\n", x[1], 100 * (y[9] - x[9]) / total }' In the all line, steal is spread across every vCPU of the machine: 8% on one core out of four becomes 2% on average. If the request handler is pinned to one core, the average hides the spike exactly where it hurts. Zero usually means the host did not make the vCPU wait during the interval.
What is CPU steal on a virtual machine?
It is the share of time when a vCPU was ready to run but waited for the hypervisor to give it a physical processor. The hypervisor maintains the counter itself, and you cannot influence it from inside the VM, only observe it. The exception is machines where steal accounting is not passed to the guest: there the metric shows zero no matter how loaded the host is.
What PSI shows
PSI (pressure stall information) appeared in kernel 4.20 and answers a different question: how much time tasks inside the system spent waiting for a resource. Statistics are kept separately for CPU, memory and I/O in /proc/pressure/cpu, memory and io. On some distributions PSI is built in but off by default. In that case you enable it with the psi=1 kernel parameter.
All three files share the same format:
$ cat /proc/pressure/cpu some avg10=0.00 avg60=0.00 avg300=0.00 total=0 full avg10=0.00 avg60=0.00 avg300=0.00 total=0 The some line is the share of time when at least one task waited for the resource. full is the share of time when all tasks that had work were waiting at once. For CPU at the system level, full is undefined: the line has been printed since kernel 5.13 only for compatibility and always shows zeros. A meaningful CPU full exists in cgroup v2, in each group's cpu.pressure file. There, all tasks of a service really can wait at the same time, while the CPU is busy with someone else's work or until the group's quota refreshes.
The avg10, avg60 and avg300 fields are moving averages over 10, 60 and 300 seconds, in percent. They are inconvenient for analyzing a specific window: smoothing drags the spike on after the load is gone. The total counter is more precise: it holds accumulated waiting time in microseconds. An increase of 250,000 µs over 5 seconds gives 5%.
# CPU PSI some over 5 seconds from the total counter, in percent t1=$(awk '/^some/ {sub("total=", "", $5); print $5}' /proc/pressure/cpu) sleep 5 t2=$(awk '/^some/ {sub("total=", "", $5); print $5}' /proc/pressure/cpu) awk -v d=$((t2 - t1)) 'BEGIN {printf "cpu some: %.2f%%\n", d / 5e6 * 100}' System PSI and a service group's PSI can differ a lot. On a VM with several applications, one service's queue easily gets lost in the overall statistics, so for an important service it is worth collecting its own cpu.pressure.
For memory and disk, both lines are meaningful at the system level too. Growing memory full means all tasks stalled at once while the kernel looked for free pages. That is a sign of RAM shortage, not neighbors, and by the way, systemd-oomd relies on it when deciding which service to stop.
How is PSI different from load average?
Load average counts the number of tasks, while PSI counts the time tasks lost waiting for a specific resource. Load average includes both running tasks and tasks in uninterruptible sleep, so a single compute thread on a single CPU VM raises it to one without any queue at all. The exception is when a queue really exists: then both metrics rise, but only PSI shows which resource is to blame.
How to set up the measurement on your own test bench
To see a neighbor's effect, two VMs must be guaranteed to share one physical core. Two VPS instances ordered from a provider may end up on different hosts, so the measurement is done on your own KVM host with libvirt. Give each VM one vCPU and pin both to the same logical processor on the host. Replace 4 with a free CPU. Keep emulator threads and the traffic generator on other cores.
If SMT is enabled on the host, pin both VMs to one logical processor, not to two threads of the same core. Neighbors on SMT threads run simultaneously, their steal barely grows, and the slowdown comes through shared core units and cache. That is also resource contention, but a different kind, and in this measurement it only muddies the picture.
# on the libvirt test host virsh vcpupin api-lab 0 4 --live virsh vcpupin load-lab 0 4 --live api-lab runs the service whose latency you measure. Load comes from Vegeta at a constant request rate. This matters: a client that waits for a response before sending the next request slows down on its own as latency grows and hides the problem.
The service itself should spend at least a few milliseconds of CPU time per request, for example computing a hash or rendering a page from a template. If it does almost nothing with the CPU, vCPU pauses will dissolve into network latency. The generator is best run on a third machine. The measurement runs in three one minute phases: baseline, CPU load on the neighbor VM, and recovery.
# on the generator machine target='GET http://api-lab:8080/' echo "$target" | vegeta attack -rate=80/s -duration=60s > base.bin # before the second phase, stress-ng starts on load-lab echo "$target" | vegeta attack -rate=80/s -duration=60s > load.bin # before the third phase, stress-ng has already stopped echo "$target" | vegeta attack -rate=80/s -duration=60s > recovery.bin for f in base load recovery; do echo "== $f"; vegeta report "$f.bin"; done The neighbor load on load-lab comes from stress-ng. One worker is enough to occupy its single vCPU. The timeout is slightly longer than the second phase, and you start the third phase once stress-ng has finished.
# on load-lab date -u +%FT%TZ uname -r stress-ng --cpu 1 --timeout 65s --metrics-brief Record metrics on api-lab at one second resolution with some margin: start recording before the first phase and stop after recovery. Sync the clocks of all three machines before the run. If node_exporter with the pressure collector already runs on the bench, you can take the same series from Prometheus by scraping the exporter every 5 seconds. Without an exporter, two terminals are enough:
# first terminal: steal per vCPU { date -u +%FT%TZ; uname -r; TZ=UTC0 LC_ALL=C stdbuf -oL mpstat -P ALL 1; } | tee steal.log # second terminal: CPU PSI once per second { uname -r while sleep 1; do printf '%s ' "$(date -u +%FT%T.%NZ)" head -n 1 /proc/pressure/cpu || break done } | tee cpu-psi.log Calculate p99 from the requests of each phase separately; you cannot average several p99 values, because the average of percentiles is not the percentile over the whole period. Record the number of errors and timeouts next to it. If some requests never got a response and p99 is calculated only from successful ones, the picture looks better than reality. Take PSI for each phase from the increase in total, not from avg10.
If a neighbor is the cause, the picture will look roughly like this:
| Phase | %steal on the service vCPU | CPU PSI some | p99 |
|---|---|---|---|
| Baseline | near zero | near zero | baseline level |
| Neighbor VM load | rises | may barely change | rises |
| Recovery | returns to baseline | near zero | returns to baseline |
An almost flat PSI in the second phase is not a bench error. If the service vCPU had a single runnable thread, nobody inside the guest waited for anyone during the host pause. The queue was outside, and only steal shows it. As a control, move the load-lab vCPU to another physical core and repeat all three phases. If the steal and p99 spike disappeared, neighboring was the cause. If it stayed, look for the cause inside the VM or in the network.
One run is not enough. Repeat the series at least three times at different times of day, and alternate the order of the control and main runs: the spread between series shows how far you can trust the result. One graph is enough for a report: steal and CPU PSI some on a shared UTC axis, both calculated from counter increases over 5 seconds, phase boundaries marked, and the kernel version, host CPU model and request rate in the caption.
How to read the metrics and what to do about them
For monitoring in Prometheus, keep service latency, steal and CPU PSI some on one graph. Steal per vCPU deserves a graph of its own next to it: averaged across the machine, a spike on one core is easy to lose. You can check metric names against the source of the cpu and pressure collectors in node_exporter.
Watch the time scale too. A ten second spike is invisible on a graph averaged over five minutes, so open a short interval for analysis, and for comparison take a neighboring window with the same traffic when the service was working normally.
# steal averaged across the machine's vCPUs 100 * avg by (job, instance) (rate(node_cpu_seconds_total{mode="steal"}[1m])) # steal per vCPU 100 * rate(node_cpu_seconds_total{mode="steal"}[1m]) # CPU PSI some for the whole system 100 * rate(node_pressure_cpu_waiting_seconds_total[1m]) | What you see | Where to look for the cause |
|---|---|
| High steal, low PSI | The host. Match steal spikes against latency growth: host pauses stretch individual requests even when the guest queue is almost empty. |
| Low steal, high PSI | Inside the VM. Check per vCPU load, thread pinning and the service's cgroup quota. |
| High steal and high PSI | Both levels at once. Clear the queue inside the VM first, then see whether the steal spikes remain. |
A service quota is easy to check through the cgroup v2 files. cpu.max holds the CPU budget per period: 25,000 out of 100,000 µs gives a quarter of a core. When the group hits that budget, nr_throttled and throttled_usec grow in cpu.stat. The limit can sit higher up the tree, so the script walks from the service to the root:
unit=api.service group=$(systemctl show -p ControlGroup --value "$unit") date -u +%FT%TZ uname -r # the service and its parent groups up to the root while [ -n "$group" ] && [ "$group" != / ]; do printf '\n%s\n' "$group" for file in cpu.max cpu.stat cpu.pressure; do path="/sys/fs/cgroup$group/$file" [ -r "$path" ] && { printf '%s\n' "$file"; cat "$path"; } done group=${group%/*} done The same table tells you when to write to your host and when to change your configuration. PSI is growing: fix your own side by raising the quota, spreading threads across vCPUs or adding cores. Steal spikes keep repeating in step with latency growth, while inside the VM there are no quotas and no overloaded vCPUs: that is a question for the provider. Attach the time in UTC, the VM ID, steal per vCPU, the request rate and p99, and the check will take minutes, not days: the host has host statistics you do not have, and they will match them against your interval. If steal gets in the way regularly, it makes sense to move to a plan with dedicated cores. Just check whether the machine gets a whole physical core or one of its SMT threads.
What level of steal is dangerous?
Dangerous steal is the steal that coincides with growth in your latency, not some percentage. A short pause breaks an API with a strict response deadline even though it barely shows in a one minute average, while a background job survives even 10% as long as it meets its deadline. That is why alerts go on latency or overdue jobs, and steal and PSI are opened during analysis. The exception is dedicated cores: there, any noticeable and recurring steal is already a reason to contact the provider.
Why you need both metrics
Steal shows whether the host is busy. PSI shows whether your task is suffering. One metric without the other gives half the picture: steal won't tell you whether the pause hurts your service, and PSI can't tell a neighbor on the host from a quota in your own container. We suggest keeping both on the dashboard, steal per vCPU, and setting alerts on latency only. I/O PSI next to them doesn't hurt either: nightly backups often cause database latency spikes with perfectly calm steal, and without that graph it is easy to blame the neighbors.
If you have no time for all this right now, start small: at the moment of the next complaint, capture mpstat -P ALL 1 and the some line from /proc/pressure/cpu. These two numbers alone show which way to dig: toward the host or inside your own machine.
There is one point to argue about: do you need steal at all if alerts are on p99? We think you do. Without steal history, a conversation with the provider comes down to "it's slow for us", while a per vCPU graph with UTC times turns it into a concrete check. On the Dedicated line of Aéza VPS, physical cores are assigned to the machine, so recurring steal there is a signal to go straight to support with that graph.