Re: [RFC PATCH 09/12] mm/huge_memory: refactor change_huge_pmd() non-present logic
From: Lorenzo Stoakes
Date: Fri Oct 24 2025 - 14:46:12 EST
On Fri, Oct 24, 2025 at 02:41:02PM -0400, Gregory Price wrote:
> On Fri, Oct 24, 2025 at 08:41:25AM +0100, Lorenzo Stoakes wrote:
> > Similar to copy_huge_pmd(), there is a large mass of open-coded logic for
> > the CONFIG_ARCH_ENABLE_THP_MIGRATION non-present entry case that does not
> > use thp_migration_supported() consistently.
> >
> > Resolve this by separating out this logic and introduce
> > change_non_present_huge_pmd().
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> > ---
> --- >8
>
> > + if (thp_migration_supported() && is_swap_pmd(*pmd)) {
> > + change_non_present_huge_pmd(mm, addr, pmd, uffd_wp,
> > + uffd_wp_resolve);
>
> You point out the original code doesn't have thp_migration_supported()
>
> is this a bug? or is it benign and just leads to it failing (nicely)
> deeper in the stack?
>
> If it's a bug, maybe this patch should be pulled out ahead of the rest?
No it's not a bug, I mean it does:
#ifdef CONFIG_ARCH_ENBLE_THP_MIGRATION
if (is_swap_pmd(*pmd)) {
...
}
#endif
Instead of the much nicer:
if (thp_migration_supported() && is_swap_pmd(*pmd)) {
}
Given:
static inline bool thp_migration_supported(void)
{
return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
}
You can see it's equivalent except we rely on compiler removing dead code when
we use thp_migration_supported() obviously (which is fine)
>
> ~Gregory
Cheers, Lorenzo