Re: [PATCH v2 4/4] mm/mlock: migrate folios out of CMA when mlocking a range
From: Lorenzo Stoakes <ljs@kernel.org>
Date: 2026-07-07 14:57:24
Also in:
linux-mm, linux-rt-devel, lkml
On Tue, Jul 07, 2026 at 09:36:17PM +0800, Wandun wrote: <snip>
quoted
diff --git a/mm/mlock.c b/mm/mlock.c index ac65de40b22b..f56c685533f5 100644 --- a/mm/mlock.c +++ b/mm/mlock.c
<snip>
quoted
+static int mlock_collect_migratable_pte_range(pmd_t *pmd, unsigned long addr, + unsigned long end, struct mm_walk *walk) +{ + struct vm_area_struct *vma = walk->vma; + struct list_head *folio_list = walk->private; + spinlock_t *ptl; + pte_t *start_pte, *pte; + pte_t ptent; + struct folio *folio; + unsigned int step = 1; + + if (!(vma->vm_flags & VM_LOCKED)) + return 0; + + ptl = pmd_trans_huge_lock(pmd, vma); + if (ptl) { + if (!pmd_present(*pmd)) { + if (unlikely(softleaf_is_migration(softleaf_from_pmd(*pmd)))) { + spin_unlock(ptl); + pmd_migration_entry_wait(vma->vm_mm, pmd); + walk->action = ACTION_AGAIN; + return 0; + } + goto out; + } + if (is_huge_zero_pmd(*pmd)) + goto out; + folio = pmd_folio(*pmd); + if (folio_is_zone_device(folio)) + goto out; + if (is_migrate_cma_page(&folio->page)) + isolate_folio_to_list(folio, folio_list); + goto out; + } + + start_pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); + if (!start_pte) { + walk->action = ACTION_AGAIN; + return 0; + } + + for (pte = start_pte; addr != end; pte += step, addr += step * PAGE_SIZE) { + step = 1; + ptent = ptep_get(pte); + if (!pte_present(ptent)) { + if (unlikely(softleaf_is_migration(softleaf_from_pte(ptent)))) { + pte_unmap_unlock(start_pte, ptl); + migration_entry_wait(vma->vm_mm, pmd, addr); + walk->action = ACTION_AGAIN; + return 0; + } + continue; + } + folio = vm_normal_folio(vma, addr, ptent); + if (!folio || folio_is_zone_device(folio)) + continue; + step = folio_mlock_step(folio, pte, addr, end); + if (is_migrate_cma_page(&folio->page))Here should be, sorry about this. if (!is_migrate_cma_page(&folio->page)) continue;
But above you do the: if (is_migrate_cma_page(&folio->page)) isolate_folio_to_list(folio, folio_list); Pattern :) so these should be consistent. But you're copy/pasting and need to not do that so it's kind of by the by. Anyway, yes I assumed you meant this. But see the main review, I am not really a fan of the implementation, overall.
Best regards Wandun
Thanks, Lorenzo