* [PATCH v3] mm/migrate: improve mlock tracking for PTE-mapped large folios
@ 2026-11-13 8:39 Wandun Chen
2026-11-13 10:22 ` David Hildenbrand (Arm)
2026-11-13 10:51 ` David Hildenbrand
0 siblings, 2 replies; 3+ messages in thread
From: Wandun Chen @ 2026-11-13 8:39 UTC (permalink / raw)
To: david, kas, hughd, akpm
Cc: ziy, matthew.brost, joshua.hahnjy, byungchul, gourry, ying.huang,
apopple, linux-mm, linux-kernel
From: Wandun Chen <chenwandun@lixiang.com>
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.
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
---
v2 -> v3:
1. Rename nr_ptes to ptes.
2. Collect Reviewed-by tag.
---
mm/migrate.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 94033c222e04..3c39d309e6bd 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -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));
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] mm/migrate: improve mlock tracking for PTE-mapped large folios
2026-11-13 8:39 [PATCH v3] mm/migrate: improve mlock tracking for PTE-mapped large folios Wandun Chen
@ 2026-11-13 10:22 ` David Hildenbrand (Arm)
2026-11-13 10:51 ` David Hildenbrand
1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-13 10:22 UTC (permalink / raw)
To: Wandun Chen, kas, hughd, akpm
Cc: ziy, matthew.brost, joshua.hahnjy, byungchul, gourry, ying.huang,
apopple, linux-mm, linux-kernel
On 11/13/26 09:39, Wandun Chen wrote:
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] mm/migrate: improve mlock tracking for PTE-mapped large folios
2026-11-13 8:39 [PATCH v3] mm/migrate: improve mlock tracking for PTE-mapped large folios Wandun Chen
2026-11-13 10:22 ` David Hildenbrand (Arm)
@ 2026-11-13 10:51 ` David Hildenbrand
1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2026-11-13 10:51 UTC (permalink / raw)
To: david, kas, hughd, akpm, Wandun Chen
Cc: ziy, matthew.brost, joshua.hahnjy, byungchul, gourry, ying.huang,
apopple, linux-mm, linux-kernel
On Fri, 13 Nov 2026 16:39:27 +0800, Wandun Chen wrote:
> 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.
>
> [...]
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
--
Cheers,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-13 10:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 8:39 [PATCH v3] mm/migrate: improve mlock tracking for PTE-mapped large folios Wandun Chen
2026-11-13 10:22 ` David Hildenbrand (Arm)
2026-11-13 10:51 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®