[Virtualization] Virtual machine vcpu tied to core physical machine


Reference article
1: Summary of KVM virtualization CPU technology
Article 2: Configuration of virtual machine CPU and mem (cputune and numatune)
Article 3: Configuration of cpu and numa in libvirt
Article 4: How to improve virtual machine performance? Take advantage of this feature to make it happen!

1. NUMA

The NUMA architecture is a technical solution for multiple CPUs to work together .
There are three main architectures for multi-CPU working together:

  1. SMP
  2. MPP
  3. NUMA

SMP and MPP will not be introduced here.
Here we only briefly introduce NUMA.
NUMA: Each processor has its own memory, and each processor can also access the memory of other processors.


2. Virtual machine xml configuration (key points)

Virtual machine configuration requirements

1. 8c16g
2. 100g-lvm
3. vcpu绑单NUMA核

Regarding the creation of lvm volumes, please refer to my article: [Operating System] Advanced Disk Management
Here is a brief description, taking as /dev/nvme0n1p1an example

# 1.物理卷
pvcreate /dev/nvme0n1p1
# 2.卷组
vgcreate vgdata /dev/nvme0n1p1
# 3.逻辑卷
lvcreate -L 10G -n testblk vgdata

Insert image description here
Virtual machine xml configuration about disk

<disk type='block' device='disk'>
	<driver name='qemu' type='raw'>
	<source dev='/dev/vgdata1/testblk'/>
	<target dev='sda' bus='virtio'/>
	<address type='pci' domain='0x0000' bus='0x08' slot='0x01' function='0x0'/>
</disk>

Let’s start preparing for core binding! ! !

1.给虚拟机cpu绑定物理机核心
2.给虚拟机cpu分组(非必须)
3.给虚拟机cpu分配内存(非必须)

Physical machine numa allocation
lscpu | grep -i numa
Insert image description here Check the virtual machine cpu usage (18289 is the virtual machine process number)
cat /proc/18289/status | grep Cpus_allowed_list
Insert image description here
The above are all checking steps and do not involve virtual machine numa binding. The following involves binding.
This article: Bind the vcpu of the virtual machine to the same numa node. The one selected this time is: NUMA node 0

Virtual machine vcpu is bound to the physical machine core

<vcpu cpuset='0-7'>8</vcpu>
<cputune>
	<vcpupin vcpu='0' cpuset='0'/>
 	<vcpupin vcpu='1' cpuset='1'/>
 	<vcpupin vcpu='2' cpuset='2'/>
 	<vcpupin vcpu='3' cpuset='3'/>
 	<vcpupin vcpu='4' cpuset='4'/>
 	<vcpupin vcpu='5' cpuset='5'/>
 	<vcpupin vcpu='6' cpuset='6'/>
 	<vcpupin vcpu='7' cpuset='7'/>
</cputune>

Attributes:
1.vcpu: corresponds to the virtual machine CPU number;
2.cpuset: corresponds to the physical machine CPU number;
(The above two lines of explanation may not be very professional, but they are easier to understand.)

Check the virtual machine core binding status on the physical machine
virsh vcpupin <vm-name>
Insert image description hereor: Check the virtual machine CPU usage (18289 is the virtual machine process number)
cat /proc/18289/status | grep Cpus_allowed_list
Insert image description here


Group virtual machine CPUs (can be omitted)

Divide the vcpu of the virtual machine into multiple nodes

<cpu mode='host-passthrough' check='none'>
    <topology sockets='1' cores='8' threads='1'/>
    <numa>
      <cell id='0' cpus='0' memory='2' unit='GiB'/>
      <cell id='1' cpus='1' memory='2' unit='GiB'/>
      <cell id='2' cpus='2' memory='2' unit='GiB'/>
      <cell id='3' cpus='3' memory='2' unit='GiB'/>
      <cell id='4' cpus='4' memory='2' unit='GiB'/>
      <cell id='5' cpus='5' memory='2' unit='GiB'/>
      <cell id='6' cpus='6' memory='2' unit='GiB'/>
      <cell id='7' cpus='7' memory='2' unit='GiB'/>
     </numa>
</cpu>
# 创建了8个node,每个node的memory为2GiB
vcpu 0 :绑定在node0
vcpu 1 :绑定在node1
vcpu 2 :绑定在node2
vcpu 3 :绑定在node3
vcpu 4 :绑定在node4
vcpu 5 :绑定在node5
vcpu 6 :绑定在node6
vcpu 7 :绑定在node7

Query the CPU node allocation en in the virtual machine
lscpu | grep -i numa
Insert image description here
, or you can not separate it. If not, the xml is as follows

<cpu mode='host-passthrough' check='none'>
    <topology sockets='1' dies='1' cluster='1' cores='8' threads='1'/>
    <numa>
      <cell id='0' cpus='0-7' memory='16' unit='GiB'/>
     </numa>
</cpu>

Bind memory according to node (can be omitted)

<numatune>
	<memory mode="strict" nodeset="0-7"/>
	<memnode cellid="0" mode="strict" nodeset="0"/>
	<memnode cellid="1" mode="strict" nodeset="1"/>
	<memnode cellid="2" mode="strict" nodeset="2"/>
	<memnode cellid="3" mode="strict" nodeset="3"/>
	<memnode cellid="4" mode="strict" nodeset="4"/>
	<memnode cellid="5" mode="strict" nodeset="5"/>
	<memnode cellid="6" mode="strict" nodeset="6"/>
	<memnode cellid="7" mode="strict" nodeset="7"/>
</numatune>

If there is no distinction

<numatune>
	<memnode cellid="0" mode="strict" nodeset="0"/>
</numatune>

Guess you like

Origin blog.csdn.net/Sanayeah/article/details/133201726