Hugepage: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Created page with "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, h...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.<ref>https://doc.dpdk.org/guides/linux_gsg/sys_reqs.html#use-of-hugepages-in-the-linux-environment</ref>
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.


<syntaxhighlight lang="bash">
#For a single-node system, the command to use is as follows (assuming that 1024 of 2MB pages are required)
echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages


# On a NUMA node system
A huge page is a memory page that is larger than 4K, On x86_64 architectures, there are two common huge page sizes: 2Mi and 1Gi. Sizes vary on other architectures.
echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
 
echo 1024 > /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages
 
</syntaxhighlight>
 
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<ref>https://linuxconfig.org/how-to-enable-hugepages-on-linux</ref>




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.<syntaxhighlight lang="bash">
default_hugepagesz=1G hugepagesz=1G hugepages=4
</syntaxhighlight>


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.<ref>https://doc.dpdk.org/guides/linux_gsg/sys_reqs.html#use-of-hugepages-in-the-linux-environment</ref>


For 64-bit applications, it is recommended to use 1 GB hugepages if the platform supports them.


<syntaxhighlight lang="bash">
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.<syntaxhighlight lang="bash">
$ 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
</syntaxhighlight>we can change  Hugepagesize <syntaxhighlight lang="bash">
$ 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
</syntaxhighlight>To make it persistent across futher reboot, add following line in /etc/sysctl.conf and reboot<syntaxhighlight lang="bash">
vm.nr_hugepages = 1024000
</syntaxhighlight><syntaxhighlight lang="bash">
#Check kernel support HugeTLB
#Check kernel support HugeTLB
$grep -i huge /boot/config-5.4.0-150-generic
$grep -i huge /boot/config-5.4.0-150-generic
Line 34: Line 56:
CONFIG_HUGETLBFS=y
CONFIG_HUGETLBFS=y
CONFIG_HUGETLB_PAGE=y
CONFIG_HUGETLB_PAGE=y
</syntaxhighlight>


$ grep -i huge /proc/meminfo
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.<syntaxhighlight lang="bash">
AnonHugePages:        0 kB
default_hugepagesz=1G hugepagesz=1G hugepages=4
ShmemHugePages:        0 kB
</syntaxhighlight>
FileHugePages:        0 kB
HugePages_Total:      0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:      2048 kB
Hugetlb:              0 kB


#HugeTBL can be setup through /etc/sysctl.conf by adding
== In gaming mode ==
vm.nr_hugepages=256
The following tweaks can improve gaming performance, but might not be optimal for other workloads/normal desktop usage.<ref>https://linux-gaming.kwindu.eu/index.php?title=Improving_performance</ref>
# also need to edit the /etc/fstab file to mount the hugepages at startup
$ sudo vi /etc/fstab by adding
huge /mnt/huge hugetlbfs defaults 0 0


$ sudo mkdir /mnt/huge
* Use Transparent Hugepages: <code>echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled</code>
$ sudo chmod 777 /mnt/huge
** With shared memory: <code>echo advise | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled</code>
 
* Use Compaction Proactiveness: <code>echo 0 | sudo tee /proc/sys/vm/compaction_proactiveness</code>
#also reboot your machine as the huge pages must be setup just after boot to make
* Disable Hugepage Defragmentation: <code>echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag</code>
#sure there is enough contiguous memory for the 2MB pages
* Lower Page Lock Unfairness: <code>echo 1 | sudo tee /proc/sys/vm/page_lock_unfairness</code>
 
</syntaxhighlight>


== Reference ==
== Reference ==
<references />
<references />
[[Category: Terminology]]
[[Category: Tuning]]

Latest revision as of 17:41, 16 June 2023

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.


A huge page is a memory page that is larger than 4K, On x86_64 architectures, there are two common huge page sizes: 2Mi and 1Gi. Sizes vary on other architectures.


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

In gaming mode

The following tweaks can improve gaming performance, but might not be optimal for other workloads/normal desktop usage.[3]

  • Use Transparent Hugepages: echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
    • With shared memory: echo advise | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled
  • Use Compaction Proactiveness: echo 0 | sudo tee /proc/sys/vm/compaction_proactiveness
  • Disable Hugepage Defragmentation: echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
  • Lower Page Lock Unfairness: echo 1 | sudo tee /proc/sys/vm/page_lock_unfairness

Reference