[PATCH v9 0/6] elf: THP-aware load segment alignment
H.J. Lu
hjl.tools@gmail.com
Tue Apr 14 04:23:47 GMT 2026
On Mon, Apr 13, 2026 at 1:35 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Apr 13, 2026 at 1:44 AM WANG Rui <wangrui@loongson.cn> wrote:
> >
>
> Hi,
>
> Please take a look at users/hjl/hugepage/master branch:
>
> https://gitlab.com/x86-glibc/glibc/-/commits/users/hjl/hugepage/marker
>
> It includes
>
> 30cd1f2158 elf: Support THP segment load with THP enabled with madvise
> 6db7f33e4e Check if linker supports -z separate-code
> 562148f88e x86-64: Disable THP segment load for tst-valgrind-smoke
>
> Please test its performance under madvise THP kernel.
I updated users/hjl/hugepage/master branch to fix a few bugs and
remove merging 2 PT_LOAD segments.
>
> > Changes since [v8]:
> > * Add a new test case.
> > * Minor formatting fixes.
> > * Mark _dl_map_segment_align with attribute_hidden.
> >
> > 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 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 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 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 4 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 5 enables this behavior by default on LoongArch64 Linux and defines
> > the default THP page size (32MB), matching the architecture’s PMD huge page
> > geometry.
> >
> > Patch 6 adds a new test for THP alignment of large load segments.
> >
> > [v8]: https://sourceware.org/pipermail/libc-alpha/2026-April/176440.html
> > [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):
> > 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: Add test for THP alignment of large load segments
> >
> > elf/dl-load.c | 4 +
> > elf/dl-load.h | 5 +-
> > elf/dl-tunables.list | 8 +
> > manual/tunables.texi | 24 +++
> > sysdeps/generic/dl-map-segment-align.h | 26 +++
> > sysdeps/unix/sysv/linux/Makefile | 8 +-
> > .../unix/sysv/linux/dl-map-segment-align.c | 55 +++++++
> > .../unix/sysv/linux/dl-map-segment-align.h | 27 ++++
> > .../unix/sysv/linux/loongarch/cpu-features.c | 6 +
> > .../loongarch/lp64/dl-map-segment-align.h | 22 +++
> > sysdeps/unix/sysv/linux/tst-thp-align.c | 149 ++++++++++++++++++
> > sysdeps/unix/sysv/linux/tst-thp-size-mod.S | 22 +++
> > 12 files changed, 352 insertions(+), 4 deletions(-)
> > create mode 100644 sysdeps/generic/dl-map-segment-align.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/loongarch/lp64/dl-map-segment-align.h
> > create mode 100644 sysdeps/unix/sysv/linux/tst-thp-align.c
> > create mode 100644 sysdeps/unix/sysv/linux/tst-thp-size-mod.S
> >
> > --
> > 2.53.0
> >
>
>
> --
> H.J.
--
H.J.
More information about the Libc-alpha
mailing list