0

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:

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.

5
  • 1
    How do you enable 1GB hugepages? In Debian Linux a kernel parametre needs to be inserted, hugepagesz=1G (and reboot of course). You can also install libhugetlbfs-bin package and view info using hugeadm command. Here's the link of debian page for hugepages: https://wiki.debian.org/Hugepages it should apply to ubuntu, which is debian based.
    – Krackout
    Commented Jun 22, 2020 at 6:38
  • Is it still necessary to do it as a boot parameter? This guide does not mention that, and led me to think that the way I did it would be sufficient. help.ubuntu.com/community/KVM%20-%20Using%20Hugepages
    – Stonecraft
    Commented Jun 22, 2020 at 10:39
  • But 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
    – Stonecraft
    Commented Jun 22, 2020 at 10:41
  • I think that the size of hugepages must be set at boot time, cannot be changed at runtime. What can be changed on the fly is the number of hugepages. But I'm not absolutely certain about, perhaps anyone else may know more on this.
    – Krackout
    Commented Jun 22, 2020 at 10:57
  • It appears that doing at runtime works fine. I put it as a job in 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 about hugeadm as an answer and I will accept it.
    – Stonecraft
    Commented Jun 22, 2020 at 13:20

2 Answers 2

1

In Debian Linux a kernel parameter needs to be inserted, hugepagesz=1G (and reboot of course). You can also install libhugetlbfs-bin package and view info using hugeadm command. The Debian wiki page on hugepades should apply to Ubuntu, which is Debian-based.

0
  1. Run virsh capabilities on your host, it will show the enabled hugepages on this host:

    # virsh capabilities
        <topology>
              <cells num='2'>
                <cell id='0'>
                  <memory unit='KiB'>16088120</memory>
                  <pages unit='KiB' size='4'>3382030</pages>
                  <pages unit='KiB' size='2048'>1250</pages>
                  <pages unit='KiB' size='1048576'>0</pages>
                  ----to be continued-----
         <cell id='1'>
                  <memory unit='KiB'>16466052</memory>
                  <pages unit='KiB' size='4'>2427937</pages>
                  <pages unit='KiB' size='2048'>1250</pages>
                  <pages unit='KiB' size='1048576'>4</pages>
                  <distances> 
    
  2. Check the system file for the usage and current status for each node:

    # cat /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/free_hugepages
    0
    # cat /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
    0
    # cat /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
    4
    # cat /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/free_hugepages
    3
    

    (node 0 has no 1G hugepage page; node 1 have 4 1G hugepage, 3 are free)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .