Using steal time to moderate CPU demands
From a virtual machine's point of view, contention for a physical CPU is clearly an undesirable thing. When contention occurs, the physical CPU will be unavailable at times when the virtual machine is trying to make use of it; that slows the execution of the workload. The situation can be worse than that, though, if a virtual CPU is preempted while holding locks needed elsewhere in the same virtual machine. At that point, threads that do still have access to a physical CPU may waste their execution time spinning on locks that the preempted CPU is no longer able to free, with possibly severe effects on performance. That is the sort of situation that causes customers to reconsider shared hosting.
Hegde's solution calls for virtual machines to take notice of when contention for physical CPUs is high and to reduce their demands to alleviate that contention.
Steal time and preferred CPUs
The amount of time that a virtual CPU spends waiting for access to a physical CPU is known as "steal time" — execution time that was "stolen" from the virtual machine by somebody else. On a Linux system, the amount of steal time experienced in a virtual machine can be read from /proc/stat, or seen with utilities like top or vmstat. The level of steal time seen by a virtual CPU can be used as a measure of how much contention for the physical CPU is being experienced.
Hegde's patch set uses steal time to help maintain (in ways that will be described shortly) a "preferred CPU" set. The preferred CPUs are a subset of the active virtual CPUs available to the virtual machine; as much as possible, the kernel on that virtual machine will try to schedule its tasks only on the preferred CPUs, leaving the others idle. When the virtual machine starts, the preferred set contains all of the active CPUs. Should the level of steal time experienced become too high, one or more CPUs will be removed from the preferred set. When steal time goes below a lower threshold, CPUs can be restored to the preferred set.
The scheduler makes use of the preferred set in few small but significant ways:
- Whenever the time comes to wake a sleeping task, that task will be placed on one of the preferred CPUs if possible.
- At each regular scheduler tick, the kernel checks whether the current CPU is in the preferred set. If not, the running task, if any, will be pushed out of the current CPU to run on one of the preferred CPUs instead.
- Load balancing will avoid moving tasks onto CPUs that are not in the preferred set.
One important exception to these rules is that a task's CPU affinities will be honored. If a task is only eligible to run on non-preferred CPUs, it will be placed on one of those CPUs. Other than that, though, this machinery will cause any CPUs that are removed from the preferred set to go mostly idle, concentrating the virtual machine's tasks on the preferred set and reducing the number of physical CPUs that the virtual machine is contending for.
One might argue that the result is simply to move the problem around. Contention arises because there is more load on the system than its physical CPUs are able to handle; that load will not go away just because the set of virtual CPUs available to a virtual machine has been reduced. What does happen, though, is that the preemption decisions are moved into the virtual machine, which has more information about the workload and which tasks should be allowed to run first. That can allow the virtual machine to run high-priority tasks, or tasks holding contended locks, before others, leading to better decisions overall.
Policy
The policy part of this system is encapsulated in a "driver" called the steal_governor. It is not actually implemented as a driver, though; it runs as a workqueue item that continually resubmits itself. It is controlled by three parameters: interval_ms regulates how often it checks the experienced steal time, while low_threshold and high_threshold set (as percentages) the amount of steal time that should lead to an increase or decrease in the number of preferred CPUs, respectively. Interestingly, these parameters do not appear in sysfs; instead, they are implemented as module parameters, a configuration method that has been discouraged in recent years. Changing any of these parameters requires unloading and reloading the steal_governor module. The default value for interval_ms is 1000ms; the low and high thresholds default to 2% and 5%, respectively.
On each iteration, the governor compares the amount of steal time to the high threshold. If that threshold is exceeded, the governor will look for a core that contains no housekeeping CPUs; all CPUs in that core will be removed from the preferred set (subject to the obvious restriction that at least one CPU must remain in the preferred set). No other immediate action is taken; the scheduler tweaks described above will eventually cause tasks to move away from the non-preferred CPUs. If, instead, the steal time drops below the low threshold, one core's worth of CPUs will be added back to the preferred set (until the point where all CPUs are preferred).
The policy implementation may be enough for a proof of concept, but it may end up falling short for real deployments. At a minimum, the ability to change the governor's parameters without unloading and reloading a module would be a clear improvement. There does not seem to be a reason why these values could not be changed directly using sysfs or sysctl knobs. Even then, though, it seems inevitable that somebody will want the ability to control the preferred CPU set from user space, or, even more inevitably, with a BPF program.
Another potential problem, of course, is the entirely voluntary nature of this mechanism; it is nice that each virtual machine can react independently, and that there is no need for an overall control or communication mechanism, but the result is a system that is dependent on universal cooperation. If only some virtual machines reduce their preferred CPU count, they will be penalized relative to those that do not. That may limit the applicability of this mechanism on multi-tenant systems where some users may not feel inclined (or may be unable) to cooperate.
On systems where cooperation can be expected, though, the results would
appear to be good. The cover letter includes data from a number of
benchmark runs showing improvements from about 2% for schbench to
over 44% for some hackbench
runs. Hegde summarizes the results as: "Many improvement across archs
especially with real life workloads
".
This patch series has been circulating since the first RFC
version in May 2025. It has been through 11 revisions — after
several RFC versions — and has evolved considerably over that time. It has
not, as yet, acquired the Acked-by or Reviewed-by tags that might indicate
readiness for merging into the mainline, but Hegde nonetheless said that
"I believe the series has now converged and is ready for merge
consideration
". Whether the scheduler maintainers agree will likely
become clear sometime after the close of the merge window.
This work was discussed at the 2026
Power Management and Scheduling in the Linux Kernel Summit; the video from that
session is available.
| Index entries for this article | |
|---|---|
| Kernel | Scheduler |
| Kernel | Virtualization |
