[v8,4/6] tunables: Add glibc.elf.thp tunable for THP-aware segment alignment

Message ID 20260405035323.558335-5-wangrui@loongson.cn (mailing list archive)
State New
Headers
Series elf: THP-aware load segment alignment |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

WANG Rui April 5, 2026, 3:53 a.m. UTC
  Introduce a new tunable, `glibc.elf.thp`, to control Transparent Huge
Page (THP) aware alignment of ELF loadable segments.

When set to `1`, the dynamic loader will attempt to align sufficiently
large `PT_LOAD` segments to the PMD huge page size when mapping them.
This increases the likelihood that the kernel backs these mappings with
Transparent Huge Pages.

The default value is `0`, which preserves the traditional page-sized
alignment and keeps existing behavior unchanged.

On systems without THP support, or when THP is disabled in the kernel,
enabling this tunable has no effect.

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
Signed-off-by: WANG Rui <wangrui@loongson.cn>
---
 elf/dl-tunables.list |  8 ++++++++
 manual/tunables.texi | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
  

Patch

diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
index 040a544c0e0..1bbf70d36fa 100644
--- a/elf/dl-tunables.list
+++ b/elf/dl-tunables.list
@@ -24,6 +24,14 @@ 
 # env_alias: An alias environment variable
 
 glibc {
+  elf {
+    thp {
+      type: INT_32
+      minval: 0
+      maxval: 1
+    }
+  }
+
   malloc {
     check {
       type: INT_32
diff --git a/manual/tunables.texi b/manual/tunables.texi
index 72769428e8c..389690d840b 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -64,6 +64,7 @@  glibc.pthread.mutex_spin_count: 100 (min: 0, max: 32767)
 glibc.rtld.optional_static_tls: 0x200 (min: 0x0, max: 0xffffffffffffffff)
 glibc.malloc.tcache_max: 0x0 (min: 0x0, max: 0xffffffffffffffff)
 glibc.malloc.check: 0 (min: 0, max: 3)
+glibc.elf.thp: 0 (min: 0, max: 1)
 @end example
 
 @menu
@@ -77,6 +78,8 @@  glibc.malloc.check: 0 (min: 0, max: 3)
 			     @theglibc{}.
 * gmon Tunables::  Tunables that control the gmon profiler, used in
                    conjunction with gprof
+* ELF Tunables::  Tunables that control Transparent Huge Page (THP)
+                  aware alignment of ELF loadable segments
 
 @end menu
 
@@ -763,3 +766,24 @@  whose size exceeds the available memory; in that case, an out of memory
 error will be printed at program startup, the profiler will be
 disabled, and no @file{gmon.out} file will be generated.
 @end deftp
+
+@node ELF Tunables
+@section ELF Tunables
+@cindex elf tunables
+
+@deftp Tunable glibc.elf.thp
+This tunable controls Transparent Huge Page (THP) aware alignment of
+ELF loadable segments.
+
+The default value is @code{0}, which preserves the traditional page-sized
+alignment for loadable segments.
+
+If set to @code{1}, glibc will attempt to align sufficiently large
+@code{PT_LOAD} segments to the PMD huge page size when mapping them
+with @code{mmap}.  This increases the likelihood that the kernel can
+back these mappings with Transparent Huge Pages.
+
+This tunable has an effect only on systems that support Transparent
+Huge Pages (currently Linux).  On other systems, or if THP is disabled
+at the kernel level, enabling this tunable has no effect.
+@end deftp