[PATCH v2 0/2] mm/ksm: keep smart scan from losing duplicate pages
From: Qiliang Yuan
Date: Thu Nov 05 2026 - 04:40:54 EST
With smart scan, which is on by default, two identical pages that become
mergeable some scans apart can stay unmerged for as long as they live:
each page times its skipped scans on its own, and once both are old they
may never be looked at in the same scan, which merging through the
unstable tree requires. This was first noticed as intermittent failures
of ksm_tests "KSM NUMA merging" in run_vmtests.sh.
Patch 1 picks the skipped scans by the global scan number, so all old
pages are looked at together every eighth scan. Over 420 pairs made
mergeable 0 to 20 scans apart, 329 and 317 merged before on two boots
and all of them after, at the cost of 10-12% more ksmd time on memory
that never merges.
Patch 2 adds a ksm_functional_tests case that fails 20/20 without patch
1 and 0/20 with it, on both boots.
Signed-off-by: Qiliang Yuan <odys.yuan@xxxxxxxxx>
---
V1 -> V2:
- Rebase onto v7.4-rc1-132-g05441d697f7f and retest there
- Drop the ksm_tests -N -m 1 numbers, as it no longer fails on this base
without the fix
- Update the ksmd cost to 10-12%, measured on this base
v1: https://lore.kernel.org/r/20261016-bug-mm-ksm-smart-scan-align-skips-v1-0-2f91d76416be@xxxxxxxxx
---
Qiliang Yuan (2):
mm/ksm: align smart scan skips with the scan number
selftests/mm: cover merging KSM pages aged by smart scan
mm/ksm.c | 24 ++---
tools/testing/selftests/mm/ksm_functional_tests.c | 108 +++++++++++++++++++++-
2 files changed, 117 insertions(+), 15 deletions(-)
---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
change-id: 20261016-bug-mm-ksm-smart-scan-align-skips-cd01e5a9889a
Best regards,
--
Qiliang Yuan <odys.yuan@xxxxxxxxx>