[PATCH 00/14] mm/ksm: merge-path cleanups and folio conversion

From: Longlong Xia

Date: Tue Sep 15 2026 - 11:18:17 EST


From: Longlong Xia <xialonglong@xxxxxxxxxx>

Clean up KSM's scan helpers, advisor naming and sysfs formatting, then
pass folios through the merge path and update the related comments.

Patches 11-13 convert the merge targets of the merge path to folios,
continuing the earlier conversion of write_protect_page(),
stable_tree_insert() and the ksm_get_folio() helpers.

Before this series the merge path talked to the stable tree in folios
but to the merge helpers in pages, so the same ksm folio was wrapped
and unwrapped at every level:

stable_tree_search() returns a folio
|
v
try_to_merge_with_ksm_page(..., &kfolio->page) <- unwrap
|
v
try_to_merge_one_page(..., kpage) <- page all the way
|
v
replace_page(vma, page, kpage, ...)
|
v
kfolio = page_folio(kpage) <- re-wrap
folio = page_folio(page) <- re-wrap

With patches 11-13 every function in the chain takes the ksm folio
directly:

stable_tree_search() returns a folio
|
v
try_to_merge_with_ksm_folio(..., kfolio)
|
v
try_to_merge_one_page(..., kfolio)
|
v
replace_page(vma, folio, kfolio, ...)
|
v
folio_page(folio, 0) only where a 4K page is needed (pte and rmap)

No functional change intended.

This series is based on next-20260914 (1a1de54f7369).

Longlong Xia (14):
mm/ksm: constify ksm_next_page_ops
mm/ksm: rename advisor_ctx to ksm_advisor_ctx
mm/ksm: use the correct format specifier for max_page_sharing
mm/ksm: add advance_scan_mm_slot() helper
mm/ksm: make remove_stable_node_chain() return bool
mm/ksm: clear all slab cache pointers in ksm_slab_free()
mm/ksm: reuse the zero page pointer for merge tracing
mm/ksm: document the two remove_rmap_item_from_tree() calls
mm/ksm: move the no_vmas label out of the if block
mm/ksm: extract ksm_begin_full_scan() from scan_get_next_rmap_item()
mm/ksm: pass folios to replace_page()
mm/ksm: take the ksm folio in try_to_merge_one_page()
mm/ksm: take the ksm folio in try_to_merge_with_ksm_page()
mm/ksm: update merge helper comments for folios

mm/ksm.c | 270 +++++++++++++++++++++++++++++++------------------------
1 file changed, 152 insertions(+), 118 deletions(-)

--
2.43.0