A patch currently residing within Andrew Morton’s “MM” memory management branch ahead of the upcoming Linux 6.16 merge window is an addition by Red Hat for introducing deferred THP insertion to khugepaged. This deferred Transparent Huge Page (THP) insertion aims to help reduce memory waste on Linux with some workloads.
Nico Pache of Red Hat has been working on this ability to optionally defer TDP insertion to khugepaged. This adds a new Linux boot option for “transparent_hugepage=” of transparent_hugepage=defer for those wanting this new deferred mode.
The Red Hat engineer explains in the MM patch commit message:
“We’ve seen cases were customers switching from RHEL7 to RHEL8 see a significant increase in the memory footprint for the same workloads.
Through our investigations we found that a large contributing factor to the increase in RSS was an increase in THP usage.
For workloads like MySQL, or when using allocators like jemalloc, it is often recommended to set /transparent_hugepages/enabled=never. This is in part due to performance degradations and increased memory waste.
This series introduces enabled=defer, this setting acts as a middle ground between always and madvise. If the mapping is MADV_HUGEPAGE, the page fault handler will act normally, making a hugepage if possible. If the allocation is not MADV_HUGEPAGE, then the page fault handler will default to the base size allocation. The caveat is that khugepaged can still operate on pages thats not MADV_HUGEPAGE.
This allows for three things… one, applications specifically designed to use hugepages will get them, and two, applications that don’t use hugepages can still benefit from them without aggressively inserting THPs at every possible chance. This curbs the memory waste, and defers the use of hugepages to khugepaged. Khugepaged can then scan the memory for eligible collapsing. Lastly there is the added benefit for those who want THPs but experience higher latency PFs. Now you can get base page performance at the PF handler and Hugepage performance for those mappings after they collapse.”
As this new “transparent_hugepage=defer” option is currently queued in Andrew Morton’s MM branch, it’s likely to be submitted for the upcoming Linux 6.16 merge window in one month if no issues arise with this current code.