Hugepage

From HPCWIKI
Jump to navigation Jump to search

Computer memory is allocated to processes as pages. Usually these pages are rather small (4K), meaning that a process consuming a lot of memory will also be consuming a lot of pages. Searching through a multitude of pages can result in system slow downs, which is why some servers can benefit from enabling huge pages.


In Database, Huge pages is especially useful on systems like database servers. Processes like MySQL and PostgreSQL can make use of huge pages if they are enabled, and will put less strain on your RAM cache[1]


In Network stack, Hugepage support is required for the large memory pool allocation used for packet buffers (the HUGETLBFS option must be enabled in the running kernel as indicated the previous section). By using hugepage allocations, performance is increased since fewer pages are needed, and therefore less Translation Lookaside Buffers (TLBs, high speed translation caches), which reduce the time it takes to translate a virtual page address to a physical page address. Without hugepages, high TLB miss rates would occur with the standard 4k page size, slowing performance.[2]


most standard on modern systems would be 2 MB while for 64-bit applications, it is recommended to use 1 GB hugepages if the platform supports them.

$ grep -i huge /proc/meminfo
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:               0 kB

we can change Hugepagesize

$ sudo sysctl -w vm.nr_hugepages=1024000  # for example 1G
[sudo] password for hpcmate: 
vm.nr_hugepages = 102400
$ grep -i huge /proc/meminfo       
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
FileHugePages:         0 kB
HugePages_Total:   127542
HugePages_Free:    127542
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:        261206016 kB

To make it persistent across futher reboot, add following line in /etc/sysctl.conf and reboot

vm.nr_hugepages = 1024000
#Check kernel support HugeTLB
$grep -i huge /boot/config-5.4.0-150-generic
CONFIG_CGROUP_HUGETLB=y
CONFIG_ARCH_WANT_GENERAL_HUGETLB=y
CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION=y
CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE=y
CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD=y
CONFIG_HAVE_ARCH_HUGE_VMAP=y
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
CONFIG_TRANSPARENT_HUGEPAGE=y
# CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS is not set
CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y
CONFIG_TRANSPARENT_HUGE_PAGECACHE=y
CONFIG_HUGETLBFS=y
CONFIG_HUGETLB_PAGE=y

Some kernel versions may not allow reserving 1 GB hugepages at run time, so reserving them at boot time may be the only option by pass the hugepages option to the kernel.

default_hugepagesz=1G hugepagesz=1G hugepages=4

Reference