Managing the number of vCPUs and cores in a virtual machine.

When creating virtual machines on various hypervisors (VMWare, KVM, Hyper-V , etc.), you may notice that sometimes a virtual machine may not see all the virtual cores (vCPUs) allocated to it. In our case, the virtual machine on KVM was allocated 8 vCPUs, Windows 10 was installed on it. However, Windows detected these cores as separate processors, of which only 2 vCPUs can be used.

Windows 10 virtual machine does not see all cores.

If you open the Windows Device Manager, you can make sure that all allocated cores are visible as 8 separate virtual processors like QEMU Virtual CPU version 2.5.

At the same time, in the properties of Windows 10 (Computer -> Properties) and in Task Manage, you can see that only 2 QEMU Virtual CPUs are available on the computer.

That is, no matter how many virtual cores you add, Windows 10 will still only be able to use two. At the same time, the neighboring virtual server with Window Server 2016 on the same hypervisor sees all 16 vCPUs allocated to it.

Number of supported processors in Windows 10.

The problem is that in desktop editions of Windows (Windows 10/8.1/7) there is a limit on the maximum number of physical processors (sockets) that a computer can use:

  • Windows 10 Home - 1 CPU
  • Windows 10 Professional - 2 CPUs
  • Windows 10 Workstation - up to 4 CPUs
  • Windows Server 2016 - up to 64 CPUs

However, this limitation does not apply to cores. Those. you can use a processor with more cores to improve performance . Most hypervisors are able to provide vCPUs in the form of processors, processor cores, or even threads. I.e instead of 8 virtual CPUs, you can provide vCPUs in the form of 2 sockets with 4 cores each. Let's consider how to allocate virtual processors in the form of cores in various virtualization systems and how to relate this to the NUMA architecture used in modern processors.

Managing virtual cores and vCPUs in KVM.

In my Windows 10 KVM virtual machine , all assigned virtual cores are considered separate processors.

To use all the CPU resources allocated to the virtual machine, the virtual machine needs to see not 8 processors, but one 8-core processor, 2 processors with 4 cores, or 1 processor with 4 cores with 2 threads. Let's try to change the way virtual cores for VMs are assigned to KVM.

Shut down the virtual machine:

# virsh shutdown server.vpn.ru – where server.vpn.io is the name of the virtual machine.
Output the current XML configuration of the KVM virtual machine:
# virsh dumpxml server.vpn.io
We are interested in a block with a description of the processors:

 <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, we just have 8 vCPUs. Let's change the configuration:
# virsh edit server.vpn.io

And after </features> add:

 <cpu mode='host-passthrough' check='none'>

<topology sockets='1' cores='4' threads='2'/>

</cpu>

Where:

  • host-passthrough - emulation mode in which the virtual machine will show the physical processor of the cluster node (node).
  • sockets='1' - indicate that the processor is 1
  • cores='4' - indicate that the processor has 4 cores
  • threads='2' - indicate that we have 2 cores each thread

Save the configuration file and start the VM. Log in to your Windows 10 guest VM and check in Task Manager or Resource Monitor that the OS sees all the dedicated vCores.

Also, the physical processor of the Intel(R) Xeon(R) Silver 4114 CPU host is now displayed in the system properties , and not the virtual one.

So we managed to solve the problem with the load on the VM, since two cores were not enough for the full operation of applications.

Configuring virtual processors and number of cores in VMWare.

You can change how the vCPU is presented for the VMWare virtual machine from the vSphere Client interface.

  • Turn off the VM and open its settings;
  • Expand the CPU section;
  • Let's change the VM configuration so that the guest OS sees 2 processors with 4 cores. Change the value of Cores per Socket to 4. This means that the guest OS will see two four-core processors (2 sockets of 4 cores);

  • Save changes and start the VM.

NUMA architecture and virtual vCPUs.

There are a few more aspects of assigning vCPUs and cores to virtual machines that you need to understand.

When assigning cores on a socket, consider the NUMA architecture (used in most modern CPUs). It is not recommended to assign more cores per socket (and total number of vCPUs) to your VM than the available cores on your physical socket/processor (NUMA node). When hosted on a single physical NUMA node, the virtual machine will be able to use the fast local RAM available on the specific NUMA node. Otherwise, processes will have to wait for a response from another NUMA node to perform the operation (which is somewhat longer).

If you assign two separate virtual sockets to the VM, then the hypervisor can run them on different NUMA nodes. Which is not the best way to affect the performance of the VM.

If the number of required vCPUs exceeds the number of cores on 1 physical socket (NUMA node), you need to create several virtual sockets (processors) with the required number of cores. It is also not advisable to use an odd number of processors (it is better to add 1 vCPU).

This will preserve the performance of the virtual machine.


For example, for 2 processor hosts with 10 cores (a total of 40 vCPUs are available, taking into account Hyper - Threading ), when setting up a vCPU for a VM, it is optimal to use the following configurations:

Required number of vCPUsNumber of virtual sockets in VM settingsThe number of cores on the virtual processor in the VM settings
oneoneone
……
tenoneten
elevenNot optimal
1226
……
202ten

In the free version of ESXi, you cannot create a VM with more than 8 vCPUs.

For example, a VM with a Microsoft SQL Server 2016 Enterprise Edition 16 vCPU in an 8-socket, 2-core configuration will perform worse than a 2-socket, 8-core configuration.

Also keep in mind that some applications are licensed by physical sockets (this was the case in older versions of SQL Server). Sometimes it's just more profitable for you to license one multi-core processor than several processors with fewer cores.

Modern versions of Windows Server are licensed differently in a virtualization environment. There are also some peculiarities of processor licensing in VMWare vSphere.

Отправить комментарий

Добавлять новые комментарии запрещено.*

Новые Старые