Rate This Document
Findability
Accuracy
Completeness
Readability

Performing Tuning on Virtual Machines

Purpose

Modify the virtual machine (VM) configuration file to configure the CPU, memory, and NIC of a VM.

Procedure

  1. Edit the VM configuration file.

    The following uses vm1 as an example.

    1
    virsh edit vm1
    
    • This command opens the configuration file of vm1 and is the prerequisite for subsequent operations. After the modification is complete, press Esc, type :wq!, and press Enter to save the file and exit.
    • The configuration file takes effect only after the VM is restarted.
      1
      2
      virsh shutdown vm1
      virsh start vm1
      
  2. Bind a vCPU to a physical CPU.
    <vcpu placement='static' cpuset='0-3'>4</vcpu>
    <cputune>
    <vcpupin vcpu='0' cpuset='0'/>
    <vcpupin vcpu='1' cpuset='1'/>
    <vcpupin vcpu='2' cpuset='2'/>
    <vcpupin vcpu='3' cpuset='3'/>
    <emulatorpin cpuset='0-3'/>
    </cputune>

    Table 1 describes the parameters in the script.

    Table 1 Parameter description

    Parameter

    Description

    cpuset

    Indicates the physical core.

    vCPU

    Indicates the virtual core.

  3. Set NUMA binding.
    <numatune>
    <memnode cellid='0' mode='strict' nodeset='0'/>
    </numatune>
    <cpu mode='host-passthrough' check='none'>
    <topology sockets='1' cores='4' threads='1'/>
    <numa>
    <cell id='0' cpus='0-3' memory='12582912' unit='KiB'/>
    </numa>
    </cpu>

    Table 2 describes the parameters in the script.

    Table 2 Parameter for NUMA binding

    Parameter

    Description

    nodeset

    Indicates the NUMA node of a physical machine.

    cellid

    Indicates the NUMA node of a VM.

  4. Set the PCIe NIC passthrough.
    <hostdev mode='subsystem' type='pci' managed='yes'>
    <source>
    <address domain='0x0000' bus='0x82' slot='0x00' function='0x0'/>
    </source>
    </hostdev>

    In the preceding command, domain, bus, slot, and function indicate the physical NIC information. You can run the lspci or ethtool -i NIC name command to view the information.

    1
    lspci
    

    Pay attention only to the leftmost number in the command output.

    "82:00.0 Ethernet controller: Huawei Technologies Co., Ltd. Hi1822 Family (4*25GE) (rev 45)"

    In the preceding information, bus-info of the NIC is a hexadecimal number. According to 82:00.0, bus='0x82', slot='0x00', function='0x0', and domain='0x0000'.

  5. Set a static huge page.
    1. Configure a static huge page for the host machine.
      Add configuration parameters in the command line when the kernel is started, that is, add the following parameters to the grub.cfg file in the /boot directory:
      transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G hugepages=200

      The size of the current host machine page table must be 4 KB if you want to configure a 1 GB huge page.

    2. Configure the huge page memory.
      <memoryBacking>
      <hugepages>
      <page size=' 1048576' unit=' KiB' nodeset='0'/>
      </hugepages>
      </memoryBacking>