[PATCH v8 0/6] elf: THP-aware load segment alignment
H.J. Lu
hjl.tools@gmail.com
Mon Apr 6 23:32:52 GMT 2026
On Sun, Apr 5, 2026 at 11:54 AM WANG Rui <wangrui@loongson.cn> wrote:
>
> OK for commit?
>
> Changes since [v7]:
> * Rename tunable glibc.elf.hugetlb to glibc.elf.thp.
> * Rebase on current master.
>
> Changes since [v6]:
> * Move MAX_THP_PAGESIZE to hugepages.
> * Skip THP mode probing when DL_MAP_DEFAULT_THP_PAGESIZE is non-zero.
>
> Changes since [v5]:
> * No functional changes.
> * Add benchmark results to the commit message.
>
> Changes since [v4]:
> * Merge malloc-hugepages into hugepages.
> * Limit the glibc.elf.hugetlb tunable maximum value to 1.
>
> Changes since [v3]:
> * Rebased on current master.
> * Resolved conflicts with recently merged changes.
> * No functional changes intended.
>
> 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.
>
> [v7]: https://sourceware.org/pipermail/libc-alpha/2026-March/175776.html
> [v6]: https://sourceware.org/pipermail/libc-alpha/2026-March/175737.html
> [v5]: https://sourceware.org/pipermail/libc-alpha/2026-March/175694.html
> [v4]: https://sourceware.org/pipermail/libc-alpha/2026-March/175644.html
> [v3]: https://sourceware.org/pipermail/libc-alpha/2026-February/175464.html
> [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.thp 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.c | 7 +--
> elf/dl-tunables.list | 8 +++
> malloc/malloc-internal.h | 2 +-
> malloc/malloc.c | 27 +++++-----
> manual/tunables.texi | 24 +++++++++
> sysdeps/generic/Makefile | 4 +-
> sysdeps/generic/dl-map-segment-align.h | 26 +++++++++
> .../{malloc-hugepages.c => hugepages.c} | 13 +++--
> .../{malloc-hugepages.h => hugepages.h} | 32 ++++++-----
> sysdeps/unix/sysv/linux/Makefile | 1 +
> .../{malloc-hugepages.h => hugepages.h} | 4 +-
> .../unix/sysv/linux/dl-map-segment-align.c | 53 +++++++++++++++++++
> .../unix/sysv/linux/dl-map-segment-align.h | 27 ++++++++++
> .../linux/{malloc-hugepages.c => hugepages.c} | 33 ++++++------
> .../unix/sysv/linux/loongarch/cpu-features.c | 6 +++
> .../loongarch/lp64/dl-map-segment-align.h | 22 ++++++++
> 18 files changed, 237 insertions(+), 61 deletions(-)
> create mode 100644 sysdeps/generic/dl-map-segment-align.h
> rename sysdeps/generic/{malloc-hugepages.c => hugepages.c} (76%)
> rename sysdeps/generic/{malloc-hugepages.h => hugepages.h} (68%)
> rename sysdeps/unix/sysv/linux/aarch64/{malloc-hugepages.h => hugepages.h} (91%)
> create mode 100644 sysdeps/unix/sysv/linux/dl-map-segment-align.c
> create mode 100644 sysdeps/unix/sysv/linux/dl-map-segment-align.h
> rename sysdeps/unix/sysv/linux/{malloc-hugepages.c => hugepages.c} (89%)
> create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h
>
> --
> 2.53.0
>
Please add some tests for this feature.
--
H.J.
More information about the Libc-alpha
mailing list