From: WANG Rui Date: Tue, 14 Apr 2026 15:17:46 +0000 (+0000) Subject: tunables: Add glibc.elf.thp tunable for THP-aware segment alignment X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9933bf832d4ea4bb1b21db435e61324c05b7b10;p=thirdparty%2Fglibc.git tunables: Add glibc.elf.thp tunable for THP-aware segment alignment 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 Signed-off-by: WANG Rui --- diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index 040a544c0e..1bbf70d36f 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 cb6a83754b..12b515c628 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