]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tunables: Add glibc.elf.thp tunable for THP-aware segment alignment
authorWANG Rui <wangrui@loongson.cn>
Tue, 14 Apr 2026 15:17:46 +0000 (15:17 +0000)
committerWilco Dijkstra <wilco.dijkstra@arm.com>
Thu, 16 Apr 2026 13:34:49 +0000 (13:34 +0000)
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
manual/tunables.texi

index 040a544c0e0fe57c2205966412ea8589bb178189..1bbf70d36fa1589a7ac230804ecbd942e469e0a7 100644 (file)
 # env_alias: An alias environment variable
 
 glibc {
+  elf {
+    thp {
+      type: INT_32
+      minval: 0
+      maxval: 1
+    }
+  }
+
   malloc {
     check {
       type: INT_32
index cb6a83754b03725c43dfc4473d5c1ef919d8f840..12b515c628f01f97f7954d7be8454381d7516094 100644 (file)
@@ -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