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
- On the host, check the huge page allocation on each NUMA node.
1cat /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.
- 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.
- Open the /etc/grub2-efi.cfg file.
1vi /etc/grub2-efi.cfg - Add the following configuration at the end of the Linux field:
1default_hugepagesz=512M hugepagesz=512M hugepages=256 pci=realloc
See the following figure.

- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the /etc/grub2-efi.cfg file.
- Reboot the server.
1reboot
- Log in to the OS again and check the huge page configuration.
1cat /proc/sys/vm/nr_hugepages
- On the host, check the huge page allocation on each NUMA node.
1cat /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).
- 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).
- Check whether hugetlbfs has been mounted.
1mount | grep hugetlbfs
If the following information is displayed, hugetlbfs has been mounted:

- 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>