Can I Use a CPU Limit to Allocate Half of a vCPU?

The title of this post is a question I’ve seen posed a few times as I prowl different virtualization communities. The good news is that we’re trying to figure out creative ways to avoid over-allocating resources to VMs. The not-so-good-news is there are still some misunderstandings on how to measure vCPU allocation and usage.

Two Kinds of CPU Capacity

The answer to the above question is, “it depends on what you’re trying to limit.” Allocating half of a vCPU is a little ambiguous because there are two types of CPU capacity and they must be measured separately. The first – and most obvious one – is GHz. The second is the ratio of virtual CPUs (vCPUs) to physical CPUs (pCPUs). If you set a CPU limit on a VM, it would only affect the first.

For example, my host has 2.0 GHz cores and I created a VM with the smallest possible CPU allocation (i.e. 1 vCPU). That VM has a capacity of 2.0 GHz and requires 1 core to be available when it needs to process something. If I set a CPU limit on that VM to 1.0 GHz, that VM can now only use half of a vCPU worth of GHz; however, it will still require a full core whenever it tries to process something. In other words, the first type of capacity (GHz) has been affected, but the second type (CPU ratio) has not.

Admins are often trying to allocate half of a vCPU because they have VMs that use less than half of the allocated GHz and they’re trying to reduce their CPU ratios. However, setting a CPU limit will not aid this. It is either using the CPU core or it’s not; there is no in between. If, however, the VM tends to run hot on CPU usage (GHz) and the admin wants to throttle the VM so it does not become a “noisy neighbor” to other VMs, a CPU limit could effectively create half a vCPU for that particular purpose, but shares or resource pools might be a better solution.


Sharing is Caring

Hopefully, you’ve found this useful. If you want to dive deeper into this topic, I would check out a previous blog post on CPU Ready.

About the Author