Skip to content
Advertisement

How to use 1GB hugepages in DPDK?

DPDK has two hugepage sizes:2MB hugepages and 1GB hugepages. I run the command below to use the 1GB hugepages:

echo 6 > /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
sudo mkdir -p /dev/hugepages_1gb
mount -t hugetlbfs nodev /dev/hugepages_1gb -o pagesize=1GB

However, when I run the command cat /proc/meminfo:

HugePages_Total:    8192
HugePages_Free:     8191
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

It still seems to use the 2MB hugepages. What should I do to use the 1GB hugepages?

Advertisement

Answer

The Hugepagesize field of /proc/meminfo is the default huge page size used by applications allocating huge pages. The available huge page sizes on your system can be seen with:

$ ls -l /sys/kernel/mm/hugepages/
total 0
drwxr-xr-x 2 root root 0 sept.   4 11:29 hugepages-1048576kB
drwxr-xr-x 2 root root 0 sept.   4 11:29 hugepages-2048kB

If you want to change the default huge page size, you can do it on the kernel command line with the default_hugepagesz parameter:

[same as hugepagesz=] The size of the default
HugeTLB page size. This is the size represented by
the legacy /proc/ hugepages APIs, used for SHM, and
default size when mounting hugetlbfs filesystems.
Defaults to the default architecture’s huge page size
if not specified.

This will define the size of the huge pages in the mounted hugetlbfs file system. Here is an example where the default size is 2M:

$ cat /proc/mounts | grep hugetlbfs
hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0

You can also specify the number of huge pages that you need by writing in the corresponding nr_hugepages file in /sys/kernel/mm/hugepages:

$ ls -l /sys/kernel/mm/hugepages/*/nr_hugepages
-rw-r--r-- 1 root root 4096 sept.   4 11:41 /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
-rw-r--r-- 1 root root 4096 sept.   4 11:41 /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

If your application starts early, it is also possible to specify the number of reserved huge pages on the kernel command line with hugepages parameter:

[HW,X86-32,IA-64] HugeTLB pages to allocate at boot.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement