mm/migrate: improve mlock tracking for PTE-mapped large folios
Subsystems (2)
PATCH v3 1/1 mm/migrate: improve mlock tracking for PTE-mapped large folios
From: Wandun Chen <[email protected]>
Commit ab521b4142aa ("mm/rmap: improve mlock tracking for large folios") mlocks a large folio when all its pages are added in one rmap operation. However, when a PTE-mapped large folio is migrated, remove_migration_pte() restores PTEs individually, passing nr_pages = 1 to the rmap helpers. As a result, PG_mlocked is not set on the destination folio.
Reclaim can restore mlock in try_to_unmap(), but Mlocked in /proc/meminfo remains undercounted until that scan occurs.
Restore mlock once the full mapping has been restored in a locked VMA under one page table lock, rather than waiting for try_to_unmap() to restore the mlock state.
---
v2 -> v3:
1. Rename nr_ptes to ptes.
2. Collect Reviewed-by tag.
--- mm/migrate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
mm/migrate.c +9 -1
@@ -353,6 +353,7 @@ static bool remove_migration_pte(struct folio *folio, {struct rmap_walk_arg *rmap_walk_arg = arg;DEFINE_FOLIO_VMA_WALK (pvmw, rmap_walk_arg->folio, vma, addr,PVMW_SYNC |PVMW_MIGRATION ); +unsigned long ptes =0 ;while (page_vma_mapped_walk (&pvmw)) {rmap_t rmap_flags =RMAP_NONE ;
@@ -446,9 +447,16 @@ static bool remove_migration_pte(struct folio *folio,else folio_add_file_rmap_pte (folio, new, vma);set_pte_at (vma->vm_mm, pvmw.address, pvmw.pte, pte); + + ptes++; } -if (READ_ONCE (vma->vm_flags) &VM_LOCKED ) +if (READ_ONCE (vma->vm_flags) &VM_LOCKED ) { +if (folio_test_large (folio) && + ptes ==folio_nr_pages (folio) && + !(pvmw.flags &PVMW_PGTABLE_CROSSED )) +mlock_vma_folio (folio, vma);mlock_drain_local (); + }trace_remove_migration_pte (pvmw.address,pte_val (pte),compound_order (new));
Signature · 1 line
2.43.0
Quoted 11 lines · Wandun Chen
From: Wandun Chen <[email protected]>
Commit
ab521b4142aa("mm/rmap: improve mlock tracking for large folios") mlocks a large folio when all its pages are added in one rmap operation. However, when a PTE-mapped large folio is migrated,remove_migration_pte()restores PTEs individually, passingnr_pages= 1 to the rmap helpers. As a result,PG_mlockedis not set on the destination folio.Reclaim can restore mlock in
try_to_unmap(), but Mlocked in/proc/meminforemains undercounted until that scan occurs.
Quoted 6 lines
Restore mlock once the full mapping has been restored in a locked VMA under one page table lock, rather than waiting for
try_to_unmap()to restore the mlock state.Reviewed-by Kiryl Shutsemau (Meta) <[email protected]>Signed-off-by Wandun Chen <[email protected]>
Signature · 3 lines
Cheers, David
Quoted 10 lines · Wandun Chen
Commit
ab521b4142aa("mm/rmap: improve mlock tracking for large folios") mlocks a large folio when all its pages are added in one rmap operation. However, when a PTE-mapped large folio is migrated,remove_migration_pte()restores PTEs individually, passingnr_pages= 1 to the rmap helpers. As a result,PG_mlockedis not set on the destination folio.Reclaim can restore mlock in
try_to_unmap(), but Mlocked in/proc/meminforemains undercounted until that scan occurs.[...]
Applied, thanks!
tree: mm/core.git
branch: migrate-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[1/1] mm/migrate: improve mlock tracking for PTE-mapped large folios
https://git.kernel.org/mm/core/c/9fa01fbb
Signature · 3 lines
Cheers, David