qemu-kvm
is launched with -mem-prealloc -mem-path /mnt/hugepages/libvort/qemu
parameters. Does this mean that the guest memory will be allocated from the hugepages on the host?
Also, libvirt defines the following in domain xml:
<memoryBacking>
<hugepages/>
<locked/>
</memoryBacking>
This basically tells the hypervisor to use hugepages
for its guest memory, and these pages will be locked in the host's memory (not allowed to be swapped out).
Are these options work together (-mem-prealloc
and libvirt's xml directive), and one supplement the other?
The <hugepages/>
element will cause guest RAM to be allocated from the default huge pages size pool, and will cause immediate allocation of those huge pages at QEMU startup. Huge pages are always locked into host RAM.
The <locked/>
element is used to control other QEMU memory allocations that are separate from guest RAM. It ensures all non-guest RAM pages are also locked into host RAM.
If you are not trying to overcommit host RAM, then using huge pages on the host side is a very good idea for maximizing performance as it improves page table hit rates. This is true regardless of whether the guest OS in turn uses huge pages. This performance benefit will apply to all workloads and all guest OS.
The KSM feature for when you are trying to overcommit host RAM (ie run many guests whose total RAM exceeds available host RAM). It tries to share RAM pages between guests to avoid risk of swapping during overcommit. KSM has a quite significant penalty in CPU consumption though, so its a tradeoff as to whether it is useful for a particular workload and/or guest OS.