[PATCH v6] elf: Support THP segment load with madvise enabled THP
H.J. Lu
hjl.tools@gmail.com
Wed Apr 29 13:26:17 GMT 2026
On Mon, Apr 27, 2026 at 9:33 PM Carlos O'Donell <carlos@redhat.com> wrote:
>
> On 4/22/26 6:30 PM, H.J. Lu wrote:
> > Changes from v5:
> >
> > 1. Xfail some tests on arm.
> >
> > Changes from v4:
> >
> > 1. Rebase against e3e8f814e5 visories: Fix spelling mistake in
> > GLIBC-SA-2026-0009.
> > 2. Drop the -z separate-code linker option check and use it unconditionally.
> > 3. Set the maximum page alignment on tst-thp-size-mod.so to THP page size.
> >
> > Changes from v3:
> >
> > 1. Fold the -z separate-code linker option check.
> > 2. Move DL_MAP_DEFAULT_THP_PAGESIZE to <hugepages.h>
> > and default it to 0.
> > 3. Don't run strace tests for cross-compiling.
> > 4. Remove return after FAIL_UNSUPPORTED in THP test.
> >
> > Changes from v2:
> >
> > 1. Keep _dl_map_segment_align name.
> > 2. Pass size_t to _dl_map_segment_align.
> > 3. Enable THP if THP is always enabled in the kernel.
> > 4. Disable THP if THP page size > MAX_THP_PAGESIZE
> >
> > Changes from v1:
> >
> > 1. Rebased against the v10 THP test patch from WANG Rui <wangrui@loongson.cn>.
> > 2. Keep DL_MAP_DEFAULT_THP_PAGESIZE.
> >
>
> Thanks for working to add the XFAIL.
>
> May you please repost this with a subject?
Done
> We reviewed this in the Monday patch review call, but we'll let the developers review.
>
>
Thanks.
--
H.J.
----
The current THP segment load approach works only when THP is enabled
with always in the kernel. If THP is enabled with madvise in the
kernel, to enable THP segment load in an application, madvise should
be called with MADV_HUGEPAGE on all THP eligible PT_LOAD segments:
1. Define DL_MAP_DEFAULT_THP_PAGESIZE in hugepages.h and default it to 0.
2. Change _dl_map_segment_align to update alignments of PT_LOAD segments,
which marks and aligns only THP eligible PT_LOAD segments to THP page size
when loading an object. This fixes BZ #34079.
3. Call _dl_executable_postprocess in rtld_setup_main_map for dynamic
executables and in LIBC_START_MAIN for static executables, which calls
madvise with MADV_HUGEPAGE on all THP eligible PT_LOAD segments in
executable. This fixes BZ #34080 for both dynamic and static executables.
4. Call _dl_postprocess_loadcmd_extra in _dl_postprocess_loadcmd, which
calls madvise with MADV_HUGEPAGE on all THP eligible PT_LOAD segments
when loading an object after they have been mapped in. This fixes
BZ #34080 for shared objects.
5. Set the maximum page alignment on THP tests to THP page size as the
default maximum page alignment may be smaller than THP page size.
6. Add tests to verify that large executable PT_LOAD segments in
executables are mapped at addresses aligned to THP page size when the
kernel is configured to use THP in "always" mode or "madvise" mode by
inspecting /proc/self/maps to check that the mapping address is aligned
to THP page size reported by the kernel. Also verify that madvise is
called with MADV_HUGEPAGE when the glibc tunable glibc.elf.thp=1 is used
and madvise isn't called with MADV_HUGEPAGE when the glibc tunable
glibc.elf.thp=0 is used.
Skip these tests if THP page size cannot be determined or if THP is not
enabled in "always" mode nor "madvise" mode.
Quote WANG Rui <wangrui@loongson.cn>:
>From benchmarking a clang build of the Linux kernel on x86_64 with
your patch in THP madvise mode, I observed that iTLB misses were
reduced, similar to what we see in THP always mode.
NB: Some THP tests fail on arm due to limitations of arm32 kABI:
https://sourceware.org/bugzilla/show_bug.cgi?id=34096
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v6-0001-elf-Support-THP-segment-load-with-madvise-enabled.patch
Type: text/x-patch
Size: 50735 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260429/1936c9de/attachment-0001.bin>
More information about the Libc-alpha
mailing list