Re: [PATCH v2 25/31] mm/ksm: look up the folio again in cmp_and_merge_page()
From: sashiko-bot
Date: Sat Dec 05 2026 - 08:00:00 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm/ksm: commit message misidentifies split site in
cmp_and_merge_page()
--
commit ed8f59006b0ed44569cb0213b72846e080677d95
Author: Chris Mason <mason@xxxxxxxxxx>
mm/ksm: look up the folio again in cmp_and_merge_page()
This commit reloads folio with page_folio(page) after calling
try_to_merge_two_pages() in cmp_and_merge_page() to avoid comparing a
stale folio pointer against tree_folio.
> try_to_merge_two_pages() gets a page (not a folio) passed and can end
> up splitting a large folio in try_to_merge_one_page().
>
> However, cmp_and_merge_page() does not look up the page's folio again
> after possibly splitting it, but compares the stale folio against
> tree_folio since commit a35d8872dae7 ("mm: remove PageTransCompound()").
[Severity: Low]
Is try_to_merge_two_pages() actually the split site that causes the stale
folio == tree_folio match?
If page and tree_page belong to the same large folio, ksmd holds two
references on it, so split_huge_page(page) inside try_to_merge_two_pages()
fails with -EAGAIN in __folio_freeze_split_anon() and leaves it unsplit.
If they belong to different folios, splitting page's folio cannot make
tree_folio equal the stale folio, so split is false and folio is never
locked.
The split that makes folio stale before unstable_tree_search_insert()
happens in try_to_merge_with_zero_page(), where ksmd holds only one
reference. When page 0 of the former large folio is later returned as
tree_page, tree_folio matches the stale folio.
Updating the commit message and comment, and reloading folio right after
try_to_merge_with_zero_page(), would match the actual split site.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-fixes_core_3-v2-0-9aad65727632@xxxxxxxxxx?part=25