How do I enable 1GB size HugePage on X86-64 platform?

环境

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • HugePage

问题

  • How do I enable 1GB size HugePage on X86-64 platform?

决议

  • To use 1GB size HugePage, CPU needs to support it. The presence of flag pdpe1gb means CPU support 1 GB size HugePage. If flag pdpe1gbis missing then it is possible to enable 1GB size HugePage.
  • Execute the following command to check CPU flag pdpe1gb in /pro/cpuinfo file.

​Raw​

# grep pdpe1gb /proc/cpuinfo | uniq
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts flush_l1d

  • The 1GB size HugePage can be enabled or disabled using the kernel boot parameters or using the files in ​​/sys​​ interface.

Steps to enable 1GB HugePage using the kernel boot parameter:

  • The kernel boot parameter ​​hugepagesz= <size>​​ is used to set the size of the HugeTLB pages (I.E. 2M, 1G) and ​​hugepages= <number>​​ is used to allocate HugeTLB pages at boot.

Red Hat Enterprsie Linux 8

  • Set ​​hugepagesz=1G​​ and ​​hugepages=5​​ parameter in ​​/boot/grub2/grubenv​​ file to allocated 5 pages of 1GB size HugePage.

​Raw​

# grep kernelopts /boot/grub2/grubenv
kernelopts=root=/dev/mapper/rhel-root ro resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet hugepagesz=1G hugepages=5

Red Hat Enterprsie Linux 7

  • Set ​​hugepagesz=1G​​ and ​​hugepages=5​​ parameter in ​​/etc/sysconfig/grub​​ file to allocated 5 pages of 1GB size HugePage.

​Raw​

# grep GRUB_CMDLINE_LINUX /etc/sysconfig/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rhel/root biosdevname=0 LANG=en_US.UTF-8 hugepagesz=1G hugepages=5

# grub2-mkconfig -o /boot/grub2/grub.cfg

  • Reboot the system.

​Raw​

# reboot

  • Verify the 1GB size HugePage allocation using the following commands.

​Raw​

# cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
5

# hugeadm --pool-list
Size Minimum Current Maximum Default
2097152 0 0 0 *
1073741824 5 5 5

Note: It is also possible to allocate both sizes of HugePage at the boot time.

  • The following kernel boot parameters will set 500 pages of 2MB size HugePage and 2 pages of 1GB HugePage on the system.

​Raw​

hugepagesz=2M hugepages=500 hugepagesz=1G hugepages=2

Steps to enable 1GB HugePage using the files in /sys interface:

  • Write the number of pages for 1 GB size HugePage in ​​/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages​​ file.

​Raw​

# echo 10 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages

  • Verify the 1GB size HugePage allocation using following commands.

​Raw​

# cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
10

# hugeadm --pool-list
Size Minimum Current Maximum Default
2097152 0 0 0 *
1073741824 10 10 10