Using Huge Pages for the VM
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. If the VM uses huge pages, you can disable transparent huge pages (see Disabling Transparent Huge Pages) to reduce overheads on the host and improve VM performance stability.
OSs differ in their unit configurations for memory huge pages, with 1 GB being the common standard. In this document, CentOS 7.6 uses 512 MB for memory huge pages. Reserve a minimum of 15% of the total memory for the host when configuring huge pages in the virtualization scenario.
- On the host, check the huge page allocation on each NUMA node.
1cat /sys/devices/system/node/node*/meminfo | grep Huge

If the value of HugePages is 0, no huge page is configured.
- Configure the VM to use 512 MB huge pages.
Reserve 15% of the total memory for the host when configuring huge pages in the KVM scenario.
For example, to create a VM with 4 vCPUs and 8GB of memory, allocate 300 huge pages of 512 MB each on the host.
- CentOS
- Edit the /boot/efi/EFI/centos/grub.cfg file on CentOS 7.6.
1vi /boot/efi/EFI/centos/grub.cfg - Add the following settings to the line starting with linux.
1default_hugepagesz=512M hugepagesz=512M hugepages=300
See the following figure.

- Edit the /boot/efi/EFI/centos/grub.cfg file on CentOS 7.6.
- openEuler
- Edit the /etc/grub2-efi.cfg file on openEuler-20.03-LTS-SP1.
1vi /etc/grub2-efi.cfg - Add the following settings to the line starting with linux.
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.
- Edit the /etc/grub2-efi.cfg file on openEuler-20.03-LTS-SP1.
- CentOS
- Restart 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 preceding figure shows that each NUMA node (numa0 to node3) has 75 x 512 MB huge pages.
You can also run the following commands to view the huge page configuration of a NUMA node.
The following uses node0 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 75 in nr_hugepages indicates that the system has allocated 75 x 512 MB huge pages to the NUMA node. The value 75 in free_hugepages indicates that the system still has 75 x 512 MB huge pages.
- Check whether hugetlbfs has been mounted.
1mount | grep hugetlbfs

Information in the preceding figure shows that hugetlbfs has been mounted.
- Edit the XML file to configure huge pages for the VM. The following is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<domain type = 'KVM'> ... <memory unit='KiB'>8388608</memory> <currentMemory unit='KiB'>83886088</currentMemory> <memoryBacking> <hugepages/> </memoryBacking> <vcpu placement = 'static' cpuset='12-15'>4</vcpu> <cputune> <vcpupin vcpu='0' cpuset='12'/> <vcpupin vcpu='1' cpuset='13'/> <vcpupin vcpu='2' cpuset='14'/> <vcpupin vcpu='3' cpuset='15'/> <emulatorpin cpuset='12-15'/> </cputune> <numatune> <memory mode='strict' nodeset='0'/> </numatune> ... </domain>
