When creating virtual machines in different hypervisors (VMWare, KVM, Hyper-V, etc.), you may see that sometimes a virtual machine may not see all virtual processor sockets (vCPU) assigned to it. In our case, 8 vCPUs were assigned to a KVM virtual machine and Windows 10 was installed on it as a guest OS. However, Windows detected these vCPUs as separate processors (not cores) and it could use only 2 of them.
Windows 10 Virtual Machine Using Only 2 Cores
If you open Windows Device Manager, you can make sure that all allocated cores are visible as 8 separate virtual processors QEMU Virtual CPU version 2.5+.
At the same time, Windows 10 properties (Computer -> Properties) and Task Manager show that only 2 QEMU Virtual processors are available.
It means that Windows 10 is able to use only 2 cores no matter how many of them you will add. At the same time, a virtual server running Windows Server 2016 on the same hypervisor can see all 16 vCPUs allocated to it.
Number of Processors Supported in Windows
The problem is that desktop Windows versions (Windows 10/8.1/7) have a restriction on the maximum number of physical processors (sockets) a computer can use:
- Windows 10 Home – 1 CPU
- Windows 10 Professional – 2 CPU
- Windows 10 Workstation – up to 4 CPU
- Windows Server 2016 – up to 64 CPU
However, this restriction is not related to the number of cores. In order to improve the performance of your virtual machine, you can use a processor with more cores. Most hypervisors can provide vCPUs as processors, processor cores or even threads. It means that instead of 8 vCPUs, you can add 2 vCPUs (2 sockets) with 4 per socket. Let’s see on how to assign virtual processors as cores in different hypervisors and how to bind it to the NUMA architecture used in modern processors.
Managing Virtual Core & vCPU in KVM
In my KVM virtual machine running Windows 10, all assigned virtual cores are considered as separate processors.
To use all CPU resources allocated to a virtual machine, it must see one 8 core processor, 2 vCPUs with 4 cores each or 1 vCPU with 4 cores in two threads instead of 8 vCPUs. Let’s try to change the allocation of virtual cores for the KVM virtual machine.
Shut down your virtual machine:
# virsh shutdown w10testvm – where w10testvm is the name of your virtual machine
Display the current XML configuration of the KVM virtual machine:
# virsh dumpxml w10testvm
We need a block describing the VM CPU settings:
<vcpu placement='static'>8</vcpu> <cputune> <shares>1000</shares> </cputune> <resource> <partition>/machine</partition> </resource> <os> <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type> <bootmenu enable='yes'/> </os> <features> <acpi/> <apic/> <pae/> </features>
As you can see, 8 vCPUs are set here. Let’s change the configuration:
# virsh edit w10testvm
Add the following block after </features>:
<cpu mode='host-passthrough' check='none'> <topology sockets='1' cores='4' threads='2'/> </cpu>
host-passthroughis the emulation mode in which the virtual machine sees the physical processor of the cluster node
sockets='1'indicates that there is one vCPU (socket)
cores='4'the processor has 4 cores per socket
threads='2'ieach core has 2 threads
Save the configuration file and start the virtual machine. Log in to the Windows 10 guest VM, run Task Manager or Resource Monitor, and make sure that the Windows sees all allocated virtual cores.
A physical processor of the host, Intel(R) Xeon(R) Silver 4114 CPU, is now displayed instead of a virtual one in the system properties.
Here is how we managed to solve the heavy load issue for the VM since two cores have not been enough for the apps to work properly.
Setting the Number of Cores per vCPU for a VMWare VM
You can change the way of vCPU presentation for a VMWare virtual machine in the vSphere Client interface.
- Shut the VM down and open its settings;
- Expand the CPU section;
- Change the VM configuration so that the guest OS can see 2 processors with 4 cores each. Change the value Cores per Socket to 4. It means that the guest OS will see two 4-core CPUs (2 sockets with 4 cores per socket);
- Save the changes and run the VM.
Virtual Machine vCPU and NUMA Architecture
There are some more aspects of assigning vCPUs and cores to virtual machines that you must understand.
When assigning the number of cores per socket, make sure whether you have NUMA architecture (used in most modern CPUs). It is not recommended to assign more cores per socket (and the total number of vCPUs) to a VM than the number of cores available on your physical socket (NUMA node). When placed on a single physical NUMA node, a virtual machine will be able to use fast local RAM available on the specific NUMA node. Otherwise, processes will have to wait for the response from another NUMA node (that takes longer time).
If you assign two separate virtual sockets to a VM, the hypervisor can run them on different NUMA nodes. It will affect the VM performance.
If the number of vCPUs needed is more than the number of cores on 1 physical socket (NUMA node), create several virtual sockets (processors) with the necessary number of cores. Also it is not recommended to use an odd number of processors (it is better to add 1 vCPU).
It allows to maintain the virtual machine performance.
For example, it is recommended to use the following configuration for a 2-processor host with 10 cores per socket (40 vCPUs are available in total including Hyper—Threading) when you configure vCPUs for a VM:
|vCPU Number Needed||Number of Virtual Sockets in the VM Settings||Number of Cores per a Virtual Processor in the VM Settings|
For example, a VM running Microsoft SQL Server 2016 Enterprise Edition with 16 vCPU (in the configuration of 8 Sockets with 2 Cores per Socket) will have poorer performance that a VM with 2 Sockets x 8 Cores per Socket.
Also remember that some applications are licensed depending on the number of physical sockets (like it was in earlier SQL Server versions). Sometimes it is more profitable to license one multicore processor than multiple processors with the less number of cores.