Configuring Hugepages to use in a virtual machine

Hugepages are an optional step during the VM configuration; it increases the RAM performance of the virtual machine. The downside is that the RAM allocated to the hugepages can not be used in the horst system, even if the guest isn’t running.

The minimum size should be not smaller then 4GB.

Check if hugepages are installed

hugeadm --explain

If you get the error message:
hugeadm:ERROR: No hugetlbfs mount points found

install the missing package first before continuing:
sudo apt install hugepages

Edit

sudo nano /etc/default/qemu-kvm

and add or uncomment
KVM_HUGEPAGES=1

-> Reboot!

After the reboot, in a terminal window, enter again:
hugeadm --explain

Total System Memory: 32098 MB

Mount Point Options
/dev/hugepages rw,relatime,pagesize=2M
/run/hugepages/kvm rw,relatime,gid=130,mode=775,pagesize=2M

Huge page pools: 
Size Minimum Current Maximum Default
2097152 0 0 0 *
1073741824 0 0 0

As you can see, hugepages are now mounted to /run/hugepages/kvm, and the hugepage size is 2097152 Bytes/(1024*1024)=2MB.

Another way to determine the hugepage size is:
grep "Hugepagesize:" /proc/meminfo

Hugepagesize: 2048 kB

Some math:
We want to reserve 8GB for Windows:
8GB = 8x1024MB = 8192MB

Our hugepage size is 2MB, so we need to reserve:
8192MB/2MB = 4096 hugepages

We need to add some % extra space for overhead (some say 2%, some say 10%), to be on the safe side you can use 4500.

Configure the hugepage pool

Again, run:

sudo nano /etc/sysctl.conf

and add the following lines into the file (a 16GB example):
# Set hugetables / hugepages for KVM single guest using 16GB RAM
vm.nr_hugepages = 8600

-> Reboot!

Set shmmax value

test again:
hugeadm --explain

Total System Memory: 32098 MB

Mount Point Options
/dev/hugepages rw,relatime,pagesize=2M
/run/hugepages/kvm rw,relatime,gid=130,mode=775,pagesize=2M

Huge page pools: 
Size Minimum Current Maximum Default
2097152 8600 8600 8600 *
1073741824 0 0 0
Huge page sizes with configured pools:

find the part that reads:
The recommended shmmax for your currently allocated huge pages is 18035507200 bytes.
To make shmmax settings persistent, add the following line to /etc/sysctl.conf:
kernel.shmmax = 18035507200

->  Do it!

sudo nano /etc/sysctl.conf
add the recommended line
kernel.shmmax = 18035507200
-> yours may differ!

in order to use hugepages, add

<memoryBacking>
  <hugepages/>
</memoryBacking>

in your virsh edit.

1 Comment

  1. […] This step is optionaland requires previous setup: See the Hugepages post for details. […]

Leave a Reply

Wir benutzen Cookies um die Nutzerfreundlichkeit der Webseite zu verbessen. Durch Deinen Besuch stimmst Du dem zu.