[PATCH v2 0/4] elf: THP-aware load segment alignment
WANG Rui
wangrui@loongson.cn
Thu Feb 26 06:33:01 GMT 2026
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 removes a redundant declaration of `_dl_map_segments` from
`dl-load.h`.
Patch 2 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 3 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 4 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 (4):
elf: Remove redundant _dl_map_segments declaration from dl-load.h
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 ++
elf/dl-load.h | 5 +-
elf/tst-decorate-maps.c | 2 +-
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 ++++++++
10 files changed, 162 insertions(+), 3 deletions(-)
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