Configuring Transparent Huge Pages

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-configuring_transparent_huge_pages

Transparent Huge Pages (THP) is an alternative solution to HugeTLB. With THP, the kernel automatically assigns huge pages to processes, so huge pages do not need to be reserved manually.

The THP feature has two modes of operation: system-wide and per-process. When THP is enabled system-wide, the kernel tries to assign huge pages to any process when it is possible to allocate huge pages and the process is using a large contiguous virtual memory area. If THP is enabled per-process, the kernel only assigns huge pages to individual processes’ memory areas specified with the madvise() system call.

Note that the THP feature only supports 2-MB pages. Transparent huge pages are enabled by default. To check the current status, run:

Copy to Clipboard Toggle word wrap

# cat /sys/kernel/mm/transparent_hugepage/enabled

To enable transparent huge pages, run:

Copy to Clipboard Toggle word wrap

# echo always > /sys/kernel/mm/transparent_hugepage/enabled

To prevent applications from allocating more memory resources than necessary, you can disable huge pages system-wide and only enable them inside MADV_HUGEPAGE madvise regions by running:

Copy to Clipboard Toggle word wrap

# echo madvise > /sys/kernel/mm/transparent_hugepage/enabled

To disable transparent huge pages, run:

Copy to Clipboard Toggle word wrap

# echo never > /sys/kernel/mm/transparent_hugepage/enabled

Sometimes, providing low latency to short-lived allocations has higher priority than immediately achieving the best performance with long-lived allocations. In such cases, direct compaction can be disabled while leaving THP enabled.

Direct compaction is a synchronous memory compaction during the huge page allocation. Disabling direct compaction provides no guarantee of saving memory, but can decrease the risk of higher latencies during frequent page faults. Note that if the workload benefits significantly from THP, the performance decreases. To disable direct compaction, run:

Copy to Clipboard Toggle word wrap

# echo madvise > /sys/kernel/mm/transparent_hugepage/defrag

For comprehensive information on transparent huge pages, see the /usr/share/doc/kernel-doc-_kernel_version_/Documentation/vm/transhuge.txt file, which is available after installing the kernel-doc package.

Updated: