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:
- Set GRUB parameters of the physical machine.
- Open the GRUB configuration file of the physical machine.
vi /etc/grub2-efi.cfg
- 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.
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the GRUB configuration file of the physical machine.
- 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.
- 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.
Parent topic: VM Configuration Tuning
