[PATCH 0/2] mm/ksm: keep smart scan from losing duplicate pages
From: Qiliang Yuan
Date: Fri Oct 16 2026 - 10:47:48 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 showed up 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, 317 merged before and all of them after,
at the cost of about 7% 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.
Signed-off-by: Qiliang Yuan <odys.yuan@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: 437a7e839def0f505277022622fc59a8b071d6cf
change-id: 20261016-bug-mm-ksm-smart-scan-align-skips-cd01e5a9889a
Best regards,
--
Qiliang Yuan <odys.yuan@xxxxxxxxx>