[PATCH v3 0/6] elf: THP-aware load segment alignment
WANG Rui
wangrui@loongson.cn
Fri Feb 27 13:23:28 GMT 2026
Changes since [v2]:
* Refactor THP detection into a new generic hugepages abstraction,
moving helpers out of malloc-hugepages.
* Add a new tunable, `glibc.elf.hugetlb`, to control THP-aware ELF
segment alignment.
* Move the Linux implementation of `_dl_map_segment_align` to
sysdeps/unix/sysv/linux/, making it generic for Linux (including
32-bit) and avoiding wordsize-64-specific overrides.
* Use `static inline` instead of `static __always_inline`.
Changes since [v1]:
* Fix CI build failure (-Wunused-function).
This patch series introduces a small extension point in the ELF loader to allow
architecture-specific adjustment of load segment alignment, and uses it to
improve Transparent Huge Page (THP) usage on Linux.
Patch 1 moves Transparent Huge Page helpers into a new generic hugepages
abstraction, so THP mode detection and default huge page size probing can be
shared between malloc and the dynamic loader. There is no functional change.
Patch 2 removes a redundant declaration of `_dl_map_segments` from
dl-load.h, avoiding `-Wunused-function` build failures and keeping the
prototype colocated with its definition.
Patch 3 adds a new helper, `_dl_map_segment_align`, which is called when
determining the maximum alignment for ELF load segments. The generic
implementation is a no-op and preserves existing behavior.
Patch 4 introduces a new tunable, `glibc.elf.hugetlb`, which controls
THP-aware alignment of ELF loadable segments. By default, the value is 0
and existing behavior is preserved.
Patch 5 provides a Linux implementation of `_dl_map_segment_align` that
opportunistically aligns large, suitably aligned, non-writable `PT_LOAD`
segments to the system’s default THP page size when THP is configured to
be used unconditionally and the tunable is enabled.
Patch 6 enables this behavior by default on LoongArch64 Linux and defines
the default THP page size (32MB), matching the architecture’s PMD huge page
geometry.
[v2]: https://sourceware.org/pipermail/libc-alpha/2026-February/175394.html
[v1]: https://sourceware.org/pipermail/libc-alpha/2026-February/175359.html
WANG Rui (6):
hugepages: Move THP helpers to generic hugepages abstraction
elf: Remove redundant _dl_map_segments declaration from dl-load.h
elf: Introduce _dl_map_segment_align hook for segment alignment tuning
tunables: Add glibc.elf.hugetlb tunable for THP-aware segment
alignment
elf: Align large load segments to PMD huge page size for THP
loongarch: Enable THP-aligned load segments by default on 64-bit
elf/dl-load.c | 4 +
elf/dl-load.h | 5 +-
elf/dl-tunables.list | 7 ++
malloc/malloc.c | 23 +++---
manual/tunables.texi | 24 ++++++
sysdeps/generic/Makefile | 8 +-
sysdeps/generic/dl-map-segment-align.h | 26 +++++++
sysdeps/generic/hugepages.c | 31 ++++++++
sysdeps/generic/hugepages.h | 35 +++++++++
sysdeps/generic/malloc-hugepages.c | 8 +-
sysdeps/generic/malloc-hugepages.h | 15 +---
sysdeps/unix/sysv/linux/Makefile | 1 +
.../sysv/linux/aarch64/malloc-hugepages.h | 2 +-
.../unix/sysv/linux/dl-map-segment-align.c | 63 +++++++++++++++
.../unix/sysv/linux/dl-map-segment-align.h | 27 +++++++
sysdeps/unix/sysv/linux/hugepages.c | 77 +++++++++++++++++++
.../unix/sysv/linux/loongarch/cpu-features.c | 6 ++
.../loongarch/lp64/dl-map-segment-align.h | 22 ++++++
sysdeps/unix/sysv/linux/malloc-hugepages.c | 59 +-------------
19 files changed, 353 insertions(+), 90 deletions(-)
create mode 100644 sysdeps/generic/dl-map-segment-align.h
create mode 100644 sysdeps/generic/hugepages.c
create mode 100644 sysdeps/generic/hugepages.h
create mode 100644 sysdeps/unix/sysv/linux/dl-map-segment-align.c
create mode 100644 sysdeps/unix/sysv/linux/dl-map-segment-align.h
create mode 100644 sysdeps/unix/sysv/linux/hugepages.c
create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h
--
2.53.0
More information about the Libc-alpha
mailing list