mm-huge_memory-refactor-copy_huge_pmd-non-present-logic.patch removed from -mm tree
The quilt patch titled
Subject: mm/huge_memory: refactor copy_huge_pmd() non-present logic
has been removed from the -mm tree. Its filename was
mm-huge_memory-refactor-copy_huge_pmd-non-present-logic.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Lorenzo Stoakes <[email protected]>
Subject: mm/huge_memory: refactor copy_huge_pmd() non-present logic
Date: Mon, 10 Nov 2025 22:21:26 +0000
Right now we are inconsistent in our use of thp_migration_supported():
static inline bool thp_migration_supported(void)
{
return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
}And simply having arbitrary and ugly #ifdefCONFIG_ARCH_ENABLE_THP_MIGRATION blocks in code.
This is exhibited in copy_huge_pmd(), which inserts a large #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION block and an if-branch which is difficult to follow
It's difficult to follow the logic of such a large function and the non-present PMD logic is clearly separate as it sits in a giant if-branch.
Therefore this patch both separates out the logic and utilises thp_migration_supported().
No functional change intended.
---
mm/huge_memory.c | 109 ++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 50 deletions(-)
mm/huge_memory.c renamed from mm/huge_memory.c~mm-huge_memory-refactor-copy_huge_pmd-non-present-logic +59 -50
@@ -1699,6 +1699,62 @@ void touch_pmd(struct vm_area_struct *vmupdate_mmu_cache_pmd (vma, addr, pmd); } +static void copy_huge_non_present_pmd ( +struct mm_struct *dst_mm,struct mm_struct *src_mm, +pmd_t *dst_pmd,pmd_t *src_pmd,unsigned long addr, +struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma, +pmd_t pmd,pgtable_t pgtable) +{ +swp_entry_t entry =pmd_to_swp_entry (pmd); +struct folio *src_folio; + +VM_WARN_ON (!is_pmd_non_present_folio_entry (pmd)); + +if (is_writable_migration_entry (entry) || +is_readable_exclusive_migration_entry (entry)) { + entry =make_readable_migration_entry (swp_offset (entry)); + pmd =swp_entry_to_pmd (entry); +if (pmd_swp_soft_dirty (*src_pmd)) + pmd =pmd_swp_mksoft_dirty (pmd); +if (pmd_swp_uffd_wp (*src_pmd)) + pmd =pmd_swp_mkuffd_wp (pmd); +set_pmd_at (src_mm, addr, src_pmd, pmd); + }else if (is_device_private_entry (entry)) { +/* +* For device private entries, since there are no +* read exclusive entries, writable = !readable +*/ +if (is_writable_device_private_entry (entry)) { + entry =make_readable_device_private_entry (swp_offset (entry)); + pmd =swp_entry_to_pmd (entry); + +if (pmd_swp_soft_dirty (*src_pmd)) + pmd =pmd_swp_mksoft_dirty (pmd); +if (pmd_swp_uffd_wp (*src_pmd)) + pmd =pmd_swp_mkuffd_wp (pmd); +set_pmd_at (src_mm, addr, src_pmd, pmd); + } + + src_folio =pfn_swap_entry_folio (entry); +VM_WARN_ON (!folio_test_large (src_folio)); + +folio_get (src_folio); +/* +* folio_try_dup_anon_rmap_pmd does not fail for +* device private entries. +*/ +folio_try_dup_anon_rmap_pmd (src_folio, &src_folio->page, + dst_vma, src_vma); + } + +add_mm_counter (dst_mm,MM_ANONPAGES ,HPAGE_PMD_NR ); +mm_inc_nr_ptes (dst_mm); +pgtable_trans_huge_deposit (dst_mm, dst_pmd, pgtable); +if (!userfaultfd_wp (dst_vma)) + pmd =pmd_swp_clear_uffd_wp (pmd); +set_pmd_at (dst_mm, addr, dst_pmd, pmd); +} +int copy_huge_pmd (struct mm_struct *dst_mm,struct mm_struct *src_mm,pmd_t *dst_pmd,pmd_t *src_pmd,unsigned long addr,struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma)
@@ -1744,59 +1800,12 @@ int copy_huge_pmd(struct mm_struct *dst_ ret = -EAGAIN ; pmd = *src_pmd; -#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION -if (unlikely (is_swap_pmd (pmd))) { -swp_entry_t entry =pmd_to_swp_entry (pmd); - -VM_WARN_ON (!is_pmd_non_present_folio_entry (pmd)); - -if (is_writable_migration_entry (entry) || -is_readable_exclusive_migration_entry (entry)) { - entry =make_readable_migration_entry (swp_offset (entry)); - pmd =swp_entry_to_pmd (entry); -if (pmd_swp_soft_dirty (*src_pmd)) - pmd =pmd_swp_mksoft_dirty (pmd); -if (pmd_swp_uffd_wp (*src_pmd)) - pmd =pmd_swp_mkuffd_wp (pmd); -set_pmd_at (src_mm, addr, src_pmd, pmd); - }else if (is_device_private_entry (entry)) { -/* -* For device private entries, since there are no -* read exclusive entries, writable = !readable -*/ -if (is_writable_device_private_entry (entry)) { - entry =make_readable_device_private_entry (swp_offset (entry)); - pmd =swp_entry_to_pmd (entry); - -if (pmd_swp_soft_dirty (*src_pmd)) - pmd =pmd_swp_mksoft_dirty (pmd); -if (pmd_swp_uffd_wp (*src_pmd)) - pmd =pmd_swp_mkuffd_wp (pmd); -set_pmd_at (src_mm, addr, src_pmd, pmd); - } - - src_folio =pfn_swap_entry_folio (entry); -VM_WARN_ON (!folio_test_large (src_folio)); - -folio_get (src_folio); -/* -* folio_try_dup_anon_rmap_pmd does not fail for -* device private entries. -*/ -folio_try_dup_anon_rmap_pmd (src_folio, &src_folio->page, - dst_vma, src_vma); - } - -add_mm_counter (dst_mm,MM_ANONPAGES ,HPAGE_PMD_NR ); -mm_inc_nr_ptes (dst_mm); -pgtable_trans_huge_deposit (dst_mm, dst_pmd, pgtable); -if (!userfaultfd_wp (dst_vma)) - pmd =pmd_swp_clear_uffd_wp (pmd); -set_pmd_at (dst_mm, addr, dst_pmd, pmd); +if (unlikely (thp_migration_supported () &&is_swap_pmd (pmd))) { +copy_huge_non_present_pmd (dst_mm, src_mm, dst_pmd, src_pmd, addr, + dst_vma, src_vma, pmd, pgtable); ret =0 ; goto out_unlock; } -#endif if (unlikely (!pmd_trans_huge (pmd))) {pte_free (dst_mm, pgtable);
_
Patches currently in -mm which might be from [email protected] are