Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/huge_memory: adjust try_to_migrate_one() and split_huge_pmd_locked()

Patch series "Clean up split_huge_pmd_locked() and remove unnecessary
folio pointers", v2.

The patch series enhances the folio verification by leveraging the
existing page_vma_mapped_walk() mechanism and removing redundant folio
pointer passing.


This patch (of 2):

split_huge_pmd_locked() currently performs redundant checks for migration
entries and folio validation that are already handled by the
page_vma_mapped_walk mechanism in try_to_migrate_one.

Specifically, page_vma_mapped_walk already ensures that:
- The folio is properly mapped in the given VMA area
- pmd_trans_huge, pmd_devmap, and migration entry validation are
performed

To leverage page_vma_mapped_walk's work, moving TTU_SPLIT_HUGE_PMD
handling to the while loop checking and removing these duplicate checks
from split_huge_pmd_locked.

Link: https://lkml.kernel.org/r/20250425103859.825879-1-gavinguo@igalia.com
Link: https://lkml.kernel.org/r/20250425103859.825879-2-gavinguo@igalia.com
Link: https://lore.kernel.org/all/98d1d195-7821-4627-b518-83103ade56c0@redhat.com/
Link: https://lore.kernel.org/all/91599a3c-e69e-4d79-bac5-5013c96203d7@redhat.com/
Signed-off-by: Gavin Guo <gavinguo@igalia.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Florent Revest <revest@google.com>
Cc: Gavin Shan <gshan@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Gavin Guo and committed by
Andrew Morton
60fbb143 7d709f49

+11 -28
+2 -19
mm/huge_memory.c
··· 3082 3082 void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address, 3083 3083 pmd_t *pmd, bool freeze, struct folio *folio) 3084 3084 { 3085 - bool pmd_migration = is_pmd_migration_entry(*pmd); 3086 - 3087 - VM_WARN_ON_ONCE(folio && !folio_test_pmd_mappable(folio)); 3088 3085 VM_WARN_ON_ONCE(!IS_ALIGNED(address, HPAGE_PMD_SIZE)); 3089 - VM_WARN_ON_ONCE(folio && !folio_test_locked(folio)); 3090 - VM_BUG_ON(freeze && !folio); 3091 - 3092 - /* 3093 - * When the caller requests to set up a migration entry, we 3094 - * require a folio to check the PMD against. Otherwise, there 3095 - * is a risk of replacing the wrong folio. 3096 - */ 3097 - if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) || pmd_migration) { 3098 - /* 3099 - * Do not apply pmd_folio() to a migration entry; and folio lock 3100 - * guarantees that it must be of the wrong folio anyway. 3101 - */ 3102 - if (folio && (pmd_migration || folio != pmd_folio(*pmd))) 3103 - return; 3086 + if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) || 3087 + is_pmd_migration_entry(*pmd)) 3104 3088 __split_huge_pmd_locked(vma, pmd, address, freeze); 3105 - } 3106 3089 } 3107 3090 3108 3091 void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
+9 -9
mm/rmap.c
··· 2292 2292 pvmw.flags = PVMW_SYNC; 2293 2293 2294 2294 /* 2295 - * unmap_page() in mm/huge_memory.c is the only user of migration with 2296 - * TTU_SPLIT_HUGE_PMD and it wants to freeze. 2297 - */ 2298 - if (flags & TTU_SPLIT_HUGE_PMD) 2299 - split_huge_pmd_address(vma, address, true, folio); 2300 - 2301 - /* 2302 2295 * For THP, we have to assume the worse case ie pmd for invalidation. 2303 2296 * For hugetlb, it could be much worse if we need to do pud 2304 2297 * invalidation in the case of pmd sharing. ··· 2316 2323 mmu_notifier_invalidate_range_start(&range); 2317 2324 2318 2325 while (page_vma_mapped_walk(&pvmw)) { 2319 - #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION 2320 2326 /* PMD-mapped THP migration entry */ 2321 2327 if (!pvmw.pte) { 2328 + if (flags & TTU_SPLIT_HUGE_PMD) { 2329 + split_huge_pmd_locked(vma, pvmw.address, 2330 + pvmw.pmd, true, NULL); 2331 + ret = false; 2332 + page_vma_mapped_walk_done(&pvmw); 2333 + break; 2334 + } 2335 + #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION 2322 2336 subpage = folio_page(folio, 2323 2337 pmd_pfn(*pvmw.pmd) - folio_pfn(folio)); 2324 2338 VM_BUG_ON_FOLIO(folio_test_hugetlb(folio) || ··· 2337 2337 break; 2338 2338 } 2339 2339 continue; 2340 - } 2341 2340 #endif 2341 + } 2342 2342 2343 2343 /* Unexpected PMD-mapped THP? */ 2344 2344 VM_BUG_ON_FOLIO(!pvmw.pte, folio);