Rate This Document
Findability
Accuracy
Completeness
Readability

Using Huge Pages for VMs

The memory huge page function ensures that all memory of a VM always exists as huge pages on the host and ensures physical memory continuity. This function effectively reduces Translation Lookaside Buffer (TLB) misses and significantly improves the performance of memory-intensive services.

To configure huge pages for VMs, set the GRUB parameters of the physical machine. Perform the following steps:

  1. Set GRUB parameters of the physical machine.
    1. Open the GRUB configuration file of the physical machine.
      vi /etc/grub2-efi.cfg
    2. Press i to enter the insert mode. Add the following huge page parameters to the end of the kernel parameters, as shown in Figure 1.
      default_hugepagesz=1024M hugepagesz=1024M hugepages=300

      Both default_hugepagesz and hugepagesz are set to 1024M (1 GB). hugepages specifies the number of allocated huge pages, which can be configured based on actual requirements.

      Figure 1 Adding huge page parameters to the end of kernel parameters
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  2. Add huge page configuration parameters to the XML configuration file of the VM. The following is an example.
    1
    2
    3
    4
    5
      <memoryBacking>
        <hugepages>
          <page size='1048576' unit='KiB'/>
        </hugepages>
      </memoryBacking>
    

    page size is set to 1048576 KiB, that is, 1,024 MB (1 GB). This value must be the same as the huge page size in the GRUB configuration.

  3. For details about the VM XML configuration file, see 2 in this section. For details about how to use huge pages for VMs, see Using Huge Pages for the VM in the KVM VM Tuning Guide.