[PATCH v10] elf: Support THP segment load with madvise enabled THP

H.J. Lu hjl.tools@gmail.com
Wed May 27 21:55:42 GMT 2026


On Thu, May 28, 2026 at 5:51 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, May 28, 2026 at 5:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Wed, May 27, 2026 at 4:29 AM Adhemerval Zanella Netto
> > <adhemerval.zanella@linaro.org> wrote:
> > >
> > >
> > >
> > > On 26/05/26 08:24, H.J. Lu wrote:
> > > > Changes in v10:
> > > >
> > > > 1. Rebased against
> > > >
> > > > commit f531cab5891cc71442dcced4abe8ecc6ef15e61f
> > > > Author: Diego Nieto Cid <dnietoc@gmail.com>
> > > > Date:   Wed May 20 23:49:27 2026 +0100
> > > >
> > > >     hurd: let the root user raise its priority
> > > >
> > > > From dce423132a5fa7ee69ba860876d7b1dc40022985 Mon Sep 17 00:00:00 2001
> > > > From: "H.J. Lu" <hjl.tools@gmail.com>
> > > > Date: Mon, 13 Apr 2026 08:23:05 +0800
> > > > Subject: [PATCH v10] elf: Support THP segment load with madvise enabled THP
> > > >
> > > > 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.
> > > > If DL_MAP_DEFAULT_THP_PAGESIZE is defined, assume kernel THP madvise mode.
> > > > If kernel THP mode is always or never, there is an extra madvise call
> > > > which has no impact.  DL_MAP_DEFAULT_THP_PAGESIZE is defined for x86 and
> > > > 64-bit loongarch.
> > > > 2. Update _dl_map_segment_align to support madvise THP mode.  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:
> > >
> > > Besides ARM, I am seeing RISCV failures as well:
> > >
> > > FAIL: elf/tst-thp-1-no-s-code-pde
> > > FAIL: elf/tst-thp-1-no-s-code-static
> > > FAIL: elf/tst-thp-1-pde
> > > FAIL: elf/tst-thp-1-static
> >
> > Is glibc configured with --enable-static-pie? If yes,
> > elf/tst-thp-1-no-s-code-static
> > and elf/tst-thp-1-static should work.
>
> I meant --enable-default-pie.
>

Can you try this on riscv?

Thanks.


--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: application/x-patch
Size: 1597 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260528/b993e451/attachment-0001.bin>


More information about the Libc-alpha mailing list