[RFC] Add GNU_PROPERTY_1_NEEDED_THP_ON_[READ_ONLY_SEGMENTS|MALLOC]

H.J. Lu hjl.tools@gmail.com
Fri Apr 17 08:42:51 GMT 2026


Transparent Huge Pages (THP) has been enabled in glibc to use THP on
THP eligible read-only segments and malloc to improve application
performance.  But there are some common issues & trade-offs of THP:

1. Latency Spikes: The background process (khugepaged) that consolidates
pages can cause temporary system freezes or high CPU usage.
2. Memory Waste: Using a 2MB page for only 4KB of data can lead to
internal fragmentation and higher memory consumption.
3. Database Incompatibility: Many databases (e.g., Oracle, MongoDB,
SAP ASE) recommend disabling THP because their non-contiguous access
patterns often trigger performance degradations.

THP shouldn't be always enabled on THP eligible read-only segments nor
in malloc automatically regardless if THP usage will improve or hurt
application performance:

https://sourceware.org/bugzilla/show_bug.cgi?id=34081

To enable developers per-application control over THP usage under madvise
THP mode, add the following bits to GNU_PROPERTY_1_NEEDED:

1. GNU_PROPERTY_1_NEEDED_THP_ON_READ_ONLY_SEGMENTS

 #define GNU_PROPERTY_1_NEEDED_THP_ON_READ_ONLY_SEGMENTS (1U << 1)

to opt-in THP usage on read-only segments in an application.  When this
bit is set on executable, run-time loader should call madvise with
MADV_HUGEPAGE on all Transparent Huge Pages (THP) eligible read-only
segments in executable and its loaded shared libraries after they are
mapped into memory under madvise THP mode.

2. GNU_PROPERTY_1_NEEDED_THP_ON_MALLOC

 #define GNU_PROPERTY_1_NEEDED_THP_ON_MALLOC (1U << 2)

to opt-in THP usage in malloc in an application.  When this bit is set on
executable, malloc should call madvise with MADV_HUGEPAGE if the
allocated size is greater than or equal to THP page size after calling
mmap to allocate memory under madvise THP mode.

Linker will set these bits in application if these bits are set in any
relocatable inputs.


-- 
H.J.


More information about the Libc-alpha mailing list