I am trying to figure out hugepages for use by KVM under Ubuntu 20.04.
If I change the number of 2048 KiB (the default size) pages, I see that is reflected in /proc/meminfo
:~$ echo 0 |sudo tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
0
:~$ cat /proc/meminfo | grep Huge
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 50331648 kB
:~$ echo 512 |sudo tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
512
:~$ cat /proc/meminfo | grep Huge
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 512
HugePages_Free: 512
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 51380224 kB
:~$
However, when I change the number of 1GB pages, I don't see anything to reflect that.
:~$ echo 0 | sudo tee /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
0
:~$ cat /proc/meminfo | grep Huge
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 512
HugePages_Free: 512
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 51380224 kB
:~$ echo 16 | sudo tee /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
16
:~$ cat /proc/meminfo | grep Huge
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 512
HugePages_Free: 512
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 51380224 kB
And as I understand it, this means that 1GB hugepages are supported by my system, right?
ls /sys/kernel/mm/hugepages
hugepages-1048576kB hugepages-2048kB
Are 1Gb pages listed somewhere else? Can I check on their status?
Edit: I can see my 1GB hugepages thanks to @Krackout, but I am still confused about what documentation I should even be following:
I am confused about varying procedures for setting up and monitoring hugepages. I seem to have got them working, but there is still quite a bit that is not clear to me.
Main resources:
- https://help.ubuntu.com/community/KVM%20-%20Using%20Hugepages
- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-memory-tuning
- https://mathiashueber.com/configuring-hugepages-use-virtual-machine/
- https://wiki.archlinux.org/index.php/KVM
- https://wiki.debian.org/Hugepages
Each of the above links describes partially overlapping procedures. It seems that differences based on kernel and distro, but it isn't clear to me what exactly they are and I can't seem to find it explcitly spelled out anywhere.
On my Ubuntu 20.04 setup, what works for me is putting the following in crontab -e
:
@reboot echo 64 | sudo tee /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
@reboot mount -t hugetlbfs -o pagesize=1G none /dev/hugepages
After which I can start a KVM VM in virt-manager containing the following XML:
<memoryBacking>
<hugepages>
<page size='1048576' unit='KiB'/>
</hugepages>
</memoryBacking>
So the way I was able to do isn't exactly what any of the guides said.
libhugetlbfs-bin
package and view info usinghugeadm
command. Here's the link of debian page for hugepages:https://wiki.debian.org/Hugepages
it should apply to ubuntu, which is debian based.hugeadm
is showing me the information I want, so you can add that as an answer. I have to admit though that I am horribly confused by the many partially-overlapping instructions for enabling hugepaths.hugeadm --pool-list
Size Minimum Current Maximum Default
2097152 512 512 512 *
1073741824 16 48 16
crontab
and it appears to be working well:hugeadm --pool-list
` Size Minimum Current Maximum Default` ` 2097152 0 0 0 *`1073741824 64 64 64
I'm still confused and annoyed by the conflicting/incomplete documentation I have read. But you can put your answer abouthugeadm
as an answer and I will accept it.