Hyper-V Program Manager
The other day I was approached by someone at Microsoft with questions about how Hyper-V schedules virtual processors, and how customers use the controls we provide. I was surprised to discover that I had not blogged on this topic.
Today I want to (begin to) fix that oversight.
Before I get started – there is one concept that I need to get straight. That is the concept of “contention for resource”. Most of the aspects of the Hyper-V CPU scheduler only come into play when all of the CPU resource on a physical computer is being used and Hyper-V has to decide who wins and who loses. This situation (all the CPU being used, and virtual machines wanting more) is where we say there is “contention for resource”. If there is free processor resource on the physical computer – there is no contention and (some) things behave differently.
Next, because it can get a bit complicated to talk about how CPU scheduling works with virtual machines and physical computers, I am going to try and use examples as often as possible. But to keep it simple I am going to use the same fictitious computer for all examples – which is a single processor quad core system (so a computer with 4 physical cores). And, unless I specify otherwise – all virtual machines will have 4 virtual processors.
With that out of the way – lets talk about the things you can configure:
Virtual machine reserve
This is configured as a percentage of the total possible CPU usage of a virtual machine. The virtual machine reserve functions in a couple of ways.
The first one is when a virtual machine is turned on. We will not let a virtual machine turn on if we determine that it is not possible to honor the virtual machine reserve. For example, if you configured each of your (4 virtual processor) virtual machines (on our fictitious computer) with a reserve of 20% we would only let you start 5 virtual machines. When you tried to start a 6th virtual machine you would get an error message stating that you cannot initialize the virtual machine.
Note that you will get this error even if all 5 running virtual machines are completely idle and are not using any CPU resource.
The second way that the virtual machine reserve is used is when there is contention for resource on the CPU. Simply put – if there is higher demand for CPU than is physically available, we will ensure that a virtual machine that needs CPU resource gets at least its CPU reserve.
What surprises some people is that we do not enforce the reserve when there is no contention for CPU resource. To explain what I mean by this:
Imaging our fictitious setup with 5 virtual machines, each with a 20% reserve, and all 5 virtual machines running and idle (0 CPU utilization). At this point in time all CPU resource has been reserved. Now, what will happen if one of these virtual machines tries to use 100% of available CPU resource while the others remain idle? In short – we will let the virtual machine have 100% of the available CPU.
The reason for this is that we can always take CPU resource back from a virtual machine. So as long as we know that the sum total of running virtual machines do not exceed 100% CPU reserve, we can let any given virtual machine chew into another virtual machines reserve, because when it is needed we can make sure the reserve is honored.
A final interesting note about the virtual machine reserve is that by default it is set to “0%” – which means the reserve is disabled. Furthermore – if you have a configuration like the one we have been discussing where all CPU is reserved, you can still start extra virtual machines as long their CPU reserve is set to 0%.
The lesson to learn here is that you should not get over-zealous with the virtual machine reserve, as things can get confusing.
How do people use the CPU reserve?
There are a couple of ways that the CPU reserve gets used:
What are the common problems involved in using a CPU reserve?
The most common issues associated with using CPU reserves are:
That is pretty much all that I have to say about the CPU reserve. Tune in tomorrow – and I will continue by discussing the “virtual machine limit”
Hello! Do things get complicated when hyper-threading is enabled?
Example: Core i-530, 2 physical cores, hyper-threading is on, so 4 logical processors. Hyper-V is running 2 virtual machines with 2 virtual processors each. If both virtual machine's reserve is set to 50 does it reserves all CPU's capacity (and 3rd VM with reserve>0 will not start) or just the half?
Btw, is hyper-threading turned on brings any goodness for Hyper-V? The host is not used for other purposes, one VM is corporate proxy/VPN Windows 2003 Server serving not very large Internet bandwidth 2MBit/s and the other is virtualized desktop Windows XP.
Hello, if I have 2 Xeon(R) CPU E5620 processors(8 cores) and have 8 VMs, how do I assign the cpus? Currently, I give each VM 4 cores.
At this stage you will only have half the system reserved (2 * 2 * .5 == 2 processors reserved). Hyper-threading may not always be beneficial - but it will not cause harm, so I would leave it on.
Hyper-V does not allow you to manually assign specific processors to specific virtual machines.
My experience is that if you have a host with multiple processors, you have an artificial limit on guest processing consumption. For example, with a quad quad-core configuration, the most any one VM can consume is 25%--if it is assigned four virtual processors--even if all the other VMs are idle.
We notice that when there is a process consuming 100% CPU in the parent partition, then all vm guests run at high CPU too. How do we explain that?
How come these settings are not available in SCVMM 2012 on a VM? SCVMM GUI should be a superset, not a subset, of the GUI?
Have a follow up question...usually processors have multipliers as 400 * 6 = 2.4 GHz. How does this value map to cores and CPUs. Does each core perform at 2.4 GHz or do all the CPU Cores crunch instructions at 2.4GHz collectively?