我要评分
获取效率
正确性
完整性
易理解

Using Hugepage Memory for VMs

Purpose

Hugepage memory ensures that all memory of a VM always exists in the form of huge pages on the host and is physically continuous. This effectively reduces TLB misses and improves the performance of services that are memory access intensive.

Procedure

  1. On the host, check the huge page allocation on each NUMA node.
    1
    cat /sys/devices/system/node/node*/meminfo | grep Huge
    

    If the values of the HugePages-related parameters are 0, no huge page is configured in the system.

  2. Configure 512 MB huge pages for the VM.

    In the KVM virtualization scenarios, reserve at least 15% of the total memory for the host when configuring huge pages.

    The following uses a VM of four vCPUs and 8 GB memory on openEuler 20.03 LTS SP1 as an example. Allocate 300 hugepages of 512 MB on the host.

    1. Open the /etc/grub2-efi.cfg file.
      1
      vi /etc/grub2-efi.cfg
      
    2. Add the following configuration at the end of the Linux field:
      1
      default_hugepagesz=512M hugepagesz=512M  hugepages=256 pci=realloc
      

      See the following figure.

    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  3. Reboot the server.
    1
    reboot
    
  4. Log in to the OS again and check the huge page configuration.
    1
    cat /proc/sys/vm/nr_hugepages
    

  5. On the host, check the huge page allocation on each NUMA node.
    1
    cat /sys/devices/system/node/node*/meminfo | grep Huge
    

    The values of the HugePages-related parameters for each NUMA node are 75, indicating that the system has configured 75 huge pages (512 MB for each page) for each NUMA node (numa 0 to numa 3).

  6. Run the following command to check the huge page configuration on a NUMA node (node 0 is used as an example):
    1
    2
    cat /sys/devices/system/node/node0/hugepages/hugepages-524288kB/nr_hugepages  
    cat /sys/devices/system/node/node0/hugepages/hugepages-524288kB/free_hugepages
    
    • The value of nr_hugepages is 75, indicating that the system configures 75 huge pages (512 MB for each page) for the NUMA node.
    • The value of free_hugepages is 75, indicating that the system has 75 remaining huge pages (512 MB for each page).
  7. Check whether hugetlbfs has been mounted.
    1
    mount | grep hugetlbfs
    

    If the following information is displayed, hugetlbfs has been mounted:

  8. Configure hugepage memory for the VM. The configuration of the VM XML file is as follows:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <domain type = 'KVM'>  
    ...  
      <memory unit='KiB'>8388608</memory>  
      <currentMemory unit='KiB'>83886088</currentMemory>  
      <memoryBacking>  
        <hugepages/>  
      </memoryBacking>  
    ...  
    </domain>