[PATCH v8 5/6] elf: Align large load segments to PMD huge page size for THP
H.J. Lu
hjl.tools@gmail.com
Sat Apr 11 00:29:26 GMT 2026
On Fri, Apr 10, 2026 at 6:19 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
>
> Hi HJ,
>
> >> The goal of this patch is simply to be aware of THP being enabled and,
> >> when possible, increase the alignment of LOAD segments so THP can work
> >> more effectively. Overall it's a passive approach, the decision of
> >> whether a mapping actually ends up using huge pages is entirely left
> >> to THP.
> >>
> >> From an impl point of view, it tries to avoid introducing any
> >> additional overhead as much as possible, including extra syscalls and
> >> the like.
>
> Indeed. And not just because it is unnecessary overhead, but also because
> there were bug reports where containers crashed on the expensive
> __get_thp_mode() call. Hence in malloc we don't call it by default.
>
> > Why can't ld.so enable THP? A single __madvise call won't kill the THP
> > performance.
>
> It won't, but my question is whether it applies to file mappings in the same
> way it works on anonymous mappings. Do you have evidence it does?
>
> Rui's patch is conservative on purpose because it is a new feature. If after
> some testing we conclude it works really well, we can improve it further.
>
A couple issues:
1. We shouldn't assume what are in /sys/kernel/mm/transparent_hugepage/enabled
nor /sys/kernel/mm/transparent_hugepage/hpage_pmd_size. We can
add a system call or AT_XXX values to get them.
2. We should support THP enabled with madvise. If the current kernel doesn't
support it, it should be updated.
3. Glibc can map PIE and DSO to address aligned to THP page size after
commit 718fdd87b1b98ef88e883a37d9c18867256fa5a4
Author: Rongwei Wang <rongwei.wang@linux.alibaba.com>
Date: Fri Dec 10 20:39:10 2021 +0800
elf: Properly align PT_LOAD segments [BZ #28676]
If THP is enabled with madvise, should kernel map PIE to address aligned to
THP page size just like THP enabled with always? If not, should we add a
marker in PIE to let kernel know that a PIE should be mapped to address
aligned to THP page size?
--
H.J.
More information about the Libc-alpha
mailing list