[PATCH 2/2] LoongArch64: Align large code segments to 32MB for THP

Florian Weimer fweimer@redhat.com
Tue Feb 24 11:13:13 GMT 2026


* WANG Rui:

> On Tue, Feb 24, 2026 at 5:30 PM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * WANG Rui:
>>
>> > +#ifdef __LP64__
>> > +  /* On LoongArch64, using 16K normal pages means we get 32M PMD huge
>> > +   * pages. So, if we align code segments of 32M or more to 32M address,
>> > +   * it really helps with THP eligibility. */
>> > +  if (__glibc_likely (GLRO(dl_pagesize) == 16384)
>> > +      && c->mapstart == 0 && c->mapoff == 0
>> > +      && (c->mapend - c->mapstart) >= 32 * 1024 * 1024
>> > +      && mapalign < 32 * 1024 * 1024 && c->prot & PROT_EXEC)
>> > +    mapalign = 32 * 1024 * 1024;
>> > +#endif
>>
>> We don't use leading * for comments.
>>
>> The size check should not be for the entire mapping, but for individual
>> load segments.  Even if the mapping is (say) 40 MiB, the optimization
>> won't work if there's a 30 MiB code mapping and a 10 MiB data mapping.
>
> Just to clarify: the size check is per individual LOAD segment, not
> for the entire mapping. In _dl_map_object_from_fd (elf/dl-load.c),
> each LOAD segment is recorded in the loadcmd array.

You are right, thanks for the correction.

Florian



More information about the Libc-alpha mailing list