[PATCH 0/3] elf: THP-aware load segment alignment
WANG Rui
wangrui@loongson.cn
Wed Feb 25 16:19:15 GMT 2026
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 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 2 provides a Linux 64-bit implementation that opportunistically aligns
large, suitably aligned load segments to the system’s default THP page size
when THP is configured to be used unconditionally, improving TLB efficiency
for large objects.
Patch 3 enables this behavior by default on LoongArch64 Linux and defines the
default THP page size (32MB), matching the architecture’s PMD huge page
geometry.
WANG Rui (3):
elf: Introduce _dl_map_segment_align hook for segment alignment tuning
elf: Align large load segments to PMD huge page size for THP
loongarch: Enable THP-aligned load segments by default and define THP
page size
elf/dl-load.c | 4 ++
sysdeps/generic/dl-map-segment-align.h | 26 +++++++++
sysdeps/unix/sysv/linux/Makefile | 1 +
.../loongarch/lp64/dl-map-segment-align.h | 23 ++++++++
.../linux/loongarch/lp64/malloc-hugepages.h | 21 +++++++
sysdeps/unix/sysv/linux/malloc-hugepages.c | 4 ++
.../linux/wordsize-64/dl-map-segment-align.c | 56 +++++++++++++++++++
.../linux/wordsize-64/dl-map-segment-align.h | 23 ++++++++
8 files changed, 158 insertions(+)
create mode 100644 sysdeps/generic/dl-map-segment-align.h
create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h
create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/malloc-hugepages.h
create mode 100644 sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.c
create mode 100644 sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.h
--
2.53.0
More information about the Libc-alpha
mailing list