7.4. 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
Note that the THP feature only supports 2-MB pages. Transparent huge pages are enabled by default. To check the current status, run:
# cat /sys/kernel/mm/transparent_hugepage/enabled
To enable transparent huge pages, run:
# 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:
# echo madvise > /sys/kernel/mm/transparent_hugepage/enabled
To disable transparent huge pages, run:
# 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 compactioncan 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:
# 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.txtfile, which is available after installing the kernel-doc package.