Re: [PATCH v2 1/2] mm/huge_memory: do not touch frozen folios in deferred_split_isolate()

From: Lance Yang

Date: Mon Aug 31 2026 - 07:16:55 EST




On 2026/8/31 17:15, Kiryl Shutsemau wrote:
From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>

deferred_split_isolate() probes each queued folio with folio_try_get().
folio_try_get() failure is treated as a lost race with folio_put(): clear
PG_partially_mapped, correct MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, take
the folio off the queue.

The folio_put() race is the most common case for !folio_try_get(), but
it is not the only option. Another scenario is folio_ref_freeze().

A zero refcount in such cases does not mean the folio is going away. It
means "don't touch me" and current deferred_split_isolate() doesn't
respect it. It can lead to unqueueing folios from the deferred list for
no reason:

CPU 0 CPU 1
--------------------------- ------------------------------
freeze a mapped folio deferred_split_scan()
folio_ref_freeze() folio_try_get() fails
folio_clear_partially_mapped()
NR_ANON_PARTIALLY_MAPPED--
folio off the queue
give up, put it back
folio_ref_unfreeze()

The folio is still partially mapped, but it is no longer a split candidate.
Nothing queues it again until part of it is unmapped once more.

Skip the folio instead: whoever freezes the folio, owns it and owner is
responsible for its fate. It also covers the folio_put() case:
__folio_put() unqueues the folio via folio_unqueue_deferred_split().

Nothing is lost by skipping. Everything that frees a queued folio
unqueues it first, and folio_unqueue_deferred_split() clears
PG_partially_mapped and brings MTHP_STAT_NR_ANON_PARTIALLY_MAPPED down
on the way:

__folio_put(), folios_put_refs() mm/folio.c
__folio_migrate_mapping() mm/migrate.c
shrink_folio_list() mm/vmscan.c

__folio_freeze_and_split_unmapped() does the same by hand, under the
list_lru lock it holds across the freeze. A freeze that ends in
folio_ref_unfreeze() leaves a folio that is still partially mapped and
still belongs on the queue.

Fixes: 8422acdc97ed ("mm: introduce a pageflag for partially mapped folios")
Reported-by: Lance Yang <lance.yang@xxxxxxxxx>
Closes: https://lore.kernel.org/all/20260824131224.73344-1-lance.yang@xxxxxxxxx/
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
Reviewed-by: Johannes Weiner <hannes@xxxxxxxxxxx>
---

LGTM.

Reviewed-by: Lance Yang <lance.yang@xxxxxxxxx>