Rate This Document
Findability
Accuracy
Completeness
Readability

Configuring the Memory Huge Page Function

Purpose

The memory huge page function ensures that all memory of a VM always exists as huge pages on the host and ensures physical continuity. This function effectively reduces Translation Lookaside Buffer (TLB) misses and significantly improves the performance of memory-intensive services. If the VM uses huge memory pages, you can disable transparent huge pages to reduce overheads on the host and improve VM performance stability.

Procedure

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

    If the value of HugePages is 0, the memory huge page function is not enabled.

  1. If the memory huge page function is not enabled, enable it first. After it is enabled, perform the step 4.

    Add the following content to the /boot/efi/EFI/centos/grub.cfg file:

    1
    default_hugepagesz=512M hugepagesz=512M hugepages=300
    

    The parameters are described as follows:

    • hugepages: defines the number of permanent large pages allocated during startup in the kernel. The default value is 0, indicating no permanent large page is allocated. The allocation is successful only when the system has enough consecutive available pages. Pages reserved by this parameter cannot be used for other purposes.
    • hugepagesz: defines the size of a huge page allocated during startup in the kernel.
    • default_hugepagesz: defines the default size of a large page allocated during startup in the kernel.

    The following is an example:

    The huge page unit varies depending on the OS. In this document, the huge page unit for CentOS 7.6 is set to 512 MB. Reserve 15% of the total memory for the host when configuring huge pages in the virtualization scenario. You can calculate the size of a huge page based on your service requirements and memory configuration in the environment.

  1. Restart the server and check the memory huge page information.
    1
    cat /proc/sys/vm/nr_hugepages
    

  1. Configure the VM to use huge memory pages
    • Method 1: Use OpenStack for Configuration
      1
      openstack flavor set FLAVOR-NAME --property hw:mem_page_size=large
      

      Create a VM by using this flavor.

      The flavor can be configured based on the actual service scenario. The possible values of the mem_page_size option and their descriptions are as follows:

      • small (default): VMs use small pages by default.
      • large: The huge memory pages are used only for VMs, and the page size is the same as that of the physical machine huge pages.
      • any: The program determines the memory pages to be used.
      • pagesize: Specifies a special page size in KB. You can also specify the unit, for example, 4 KB, 2 MB, 2048 or 1 GB.
    • Method 2: Use virsh for Configuration

      Edit the XML file on the compute node. For details about how to query instances, see Binding the VMs to Cores. The following is an example of the configuration file:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      <domain type = 'KVM'>
      ...
      <memoryBacking>
      <hugepages>
       <page size='524288' unit='KiB' nodeset='0'/>
          </hugepages>
       </memoryBacking>
      ...
      </domain>
      
  1. Disable transparent huge pages on physical machines to ensure stable performance.
    1
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    

    To enable the transparent huge pages, run the following command:

    1
    echo always > /sys/kernel/mm/transparent_hugepage/enabled
    

Recommended Policy

This function applies to scenarios where a small number of VMs are deployed. If there are a large number of VMs, you can directly use small memory pages.

Note

Huge memory pages can be allocated to VMs, but VMs may not use them. If huge memory pages are not enabled for a VM, the VM will identify the pages as small pages.