From: sashiko-bot@kernel.org
To: "Joanne Koong" <joannelkoong@gmail.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>
Cc: "Kiryl Shutsemau" <kas@kernel.org>,
"Usama Arif" <usama.arif@linux.dev>,
"Barry Song" <baohua@kernel.org>,
"Lance Yang" <lance.yang@linux.dev>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Rik van Riel" <riel@surriel.com>,
"Liam R . Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Harry Yoo" <harry@kernel.org>, "Jann Horn" <jannh@google.com>,
"Zi Yan" <ziy@nvidia.com>, "SJ Park" <sj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
linux-mm@kvack.org
Subject: Re: [PATCH v1] mm/rmap: fix migration entries being treated as partial unmaps
Date: Tue, 10 Nov 2026 22:13:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-207814@kernel.org> (raw)
In-Reply-To: <20261109220958.2071687-1-joannelkoong@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm/rmap: PMD migration entries still queue folios for
deferred split
- [Low] mm/rmap: try_to_migrate_one() misses deferred split on last PTE
unmap
--
commit 685cbbfa9eaed572b053e5452f3d93b8fec2771b
Author: Joanne Koong <joannelkoong@gmail.com>
mm/rmap: fix migration entries being treated as partial unmaps
This commit adds a may_defer_split parameter to __folio_remove_rmap() and
passes false from try_to_migrate_one() when installing PTE migration
entries, preventing temporary migration entries from queueing anonymous
large folios for deferred splitting.
> diff --git a/mm/rmap.c b/mm/rmap.c
> index fa34e1ccbd8f2..e5d17481c0c01 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
[ ... ]
> @@ -1938,7 +1943,8 @@ void folio_remove_rmap_pmd(struct folio *folio, struct page *page,
> struct vm_area_struct *vma)
> {
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> - __folio_remove_rmap(folio, page, HPAGE_PMD_NR, vma, PGTABLE_LEVEL_PMD);
> + __folio_remove_rmap(folio, page, HPAGE_PMD_NR, vma, PGTABLE_LEVEL_PMD,
> + true);
> #else
> WARN_ON_ONCE(true);
> #endif
[Severity: Medium]
Can replacing a PMD mapping with migration entries still queue a fully
mapped folio for deferred split?
When try_to_migrate_one() replaces a PMD via set_pmd_migration_entry() or
split_huge_pmd_locked(..., true) -> __split_huge_pmd_locked(), both paths
call folio_remove_rmap_pmd(), which unconditionally passes
may_defer_split = true to __folio_remove_rmap().
If the folio is PMD-mapped in a parent process after fork() and the child
has unmapped or CoW-faulted one subpage so its VMA holds 511 PTE mappings,
removing the parent's PMD rmap sees 0 < nr < nr_pmdmapped (or
last && nr < folio_large_nr_pages(folio) under CONFIG_NO_PAGE_MAPCOUNT)
and calls deferred_split_folio(folio, true). migrate_folio_move() then
propagates PG_partially_mapped to the destination folio, causing the
shrinker to split the migrated THP even though all 512 pages remain mapped
in the parent.
[ ... ]
> @@ -2516,6 +2523,8 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
> mmu_notifier_invalidate_range_start(&range);
>
> while (page_vma_mapped_walk(&pvmw)) {
> + bool may_defer_split = true;
> +
> /* PMD-mapped THP migration entry */
> if (!pvmw.pte) {
> __maybe_unused unsigned long pfn;
> @@ -2772,12 +2781,20 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
> * No need to invalidate here it will synchronize on
> * against the special swap migration pte.
> */
> +
> + /*
> + * The folio only looks partially unmapped while this PTE
> + * holds a migration entry, which is later turned back
> + * into a mapping. Don't queue it for deferred split.
> + */
> + may_defer_split = false;
> }
>
> if (unlikely(folio_test_hugetlb(folio)))
> hugetlb_remove_rmap(folio);
> else
> - folio_remove_rmap_pte(folio, subpage, vma);
> + __folio_remove_rmap(folio, subpage, 1, vma,
> + PGTABLE_LEVEL_PTE, may_defer_split);
[Severity: Low]
Does try_to_migrate_one() miss queueing the folio for deferred split when
the last mapped PTE is unmapped via PageHWPoison(subpage) or
pte_unused(pteval)?
Each earlier PTE converted to a migration entry calls
__folio_remove_rmap() with may_defer_split = false, which still decrements
_nr_pages_mapped (and _large_mapcount). When the final mapped PTE is
genuinely unmapped with may_defer_split = true, _nr_pages_mapped (or
_large_mapcount under CONFIG_NO_PAGE_MAPCOUNT) drops from 1 to 0, so
__folio_remove_rmap() sees the folio as completely unmapped and sets
partially_mapped = false. Once remove_migration_ptes() restores the
earlier migration entries, the folio is left partially mapped without
PG_partially_mapped set or being queued on deferred_split_lru.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109220958.2071687-1-joannelkoong@gmail.com?part=1
prev parent reply other threads:[~2026-11-10 22:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 22:09 [PATCH v1] mm/rmap: fix migration entries being treated as partial unmaps Joanne Koong
2026-11-10 11:48 ` David Hildenbrand (Arm)
2026-11-10 20:21 ` Joanne Koong
2026-11-10 20:55 ` David Hildenbrand (Arm)
2026-11-10 21:05 ` Zi Yan
2026-11-10 23:26 ` Joanne Koong
2026-11-10 22:13 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-207814@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=joannelkoong@gmail.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=riel@surriel.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sj@kernel.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox