Re: [PATCH v5] binfmt_elf: Align eligible read-only PT_LOAD segments to PMD_SIZE for THP
From: WANG Rui
Date: Sat Mar 21 2026 - 10:21:48 EST
One clarification regarding my earlier comment about compatibility with
cont-pte.
What I meant there is that the alignment logic in my patch does work for
systems with 4K and 16K base pages, where the PMD size remains within a
practical range. In those configurations, providing PMD-level alignment
already creates the conditions needed for both THP collapse and cont-pte
coalescing.
This does not fully extend to 64K base page systems. There the PMD size
can be quite large (e.g. 512M), which exceeds the 32M cap used in my
patch, so PMD-sized alignment may not be achievable in practice.
One way to structure this could be to treat alignment in a layered manner.
My patch focuses on establishing a reliable PMD-level alignment baseline
so that THP has the opportunity to form large mappings where it is practical.
On top of that, Usama's work can further improve behavior at smaller
granularities, for example by enabling cont-pte mappings when PMD alignment
is not feasible.
/* skip non-power of two alignments as invalid */
if (!is_power_of_2(p_align))
continue;
if (p_align < PMD_SIZE && should_align_to_pmd(&cmds[i]))
p_align = PMD_SIZE;
+ else if (p_align < CONT_PTE_SIZE && should_align_to_cont_pte(&cmds[i]))
+ p_align = CONT_PTE_SIZE;
alignment = max(alignment, p_align);
}
}
With that separation of roles, the two approaches complement each other,
and we can get the benefit of both without changing the core alignment
policy in binfmt_elf.
Thanks,
Rui