Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: disable smart scan for ksm_tests
@ 2026-08-23 18:43 Zenghui Yu
  2026-08-24 10:33 ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 3+ messages in thread
From: Zenghui Yu @ 2026-08-23 18:43 UTC (permalink / raw)
  To: linux-mm, linux-kselftest, linux-kernel
  Cc: akpm, david, xu.xin16, chengming.zhou, shr, ljs, vbabka, rppt,
	surenb, mhocko, shuah, Zenghui Yu (Huawei)

From: "Zenghui Yu (Huawei)" <zenghui.yu@linux.dev>

The "KSM NUMA merging" test allocates two identical pages on two NUMA nodes
and verifies KSM will merge these two pages after 2 scans (see
ksm_merge_pages()). But when smart scan is enabled, pages that have
previously not been de-duplicated may get skipped for some scans. Verifying
KSM behavior after only 2 scans may not be enough.

 $ ./ksm_tests -N -d
 TAP version 13
 1..1
 pages_shared      : 0
 pages_sharing     : 0
 max_page_sharing  : 256
 full_scans        : 211
 pages_unshared    : 1
 pages_volatile    : 2
 stable_node_chains: 0
 stable_node_dups  : 0
 general_profit    : -128
 ksm_rmap_items 2
 ksm_zero_pages 0
 ksm_merging_pages 0
 ksm_process_profit -128
 ksm_merge_any: no
 ksm_mergeable: yes
 not ok 1 KSM NUMA merging
 # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0

This specific test fails because KSM started scanning the second page
whilst the first page had already been scanned for 16 times
(ksm_rmap_item::age of page 0 is 16 greater than page 1). It's not
difficult to infer that should_skip_rmap_item() cannot be false at the same
time for these two pages - they cannot be merged even after 211 full scans.

Given the current implementation of smart scan, it may not be appropriate
to enable it for selftests. Let's disable it for now.

Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>
---
 tools/testing/selftests/mm/ksm_tests.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
index 5fd7792a0d47..e72681090ff9 100644
--- a/tools/testing/selftests/mm/ksm_tests.c
+++ b/tools/testing/selftests/mm/ksm_tests.c
@@ -33,6 +33,7 @@ struct ksm_sysfs {
 	unsigned long pages_to_scan;
 	unsigned long run;
 	unsigned long sleep_millisecs;
+	unsigned long smart_scan;
 	unsigned long stable_node_chains_prune_millisecs;
 	unsigned long use_zero_pages;
 };
@@ -293,6 +294,7 @@ static int ksm_save_def(struct ksm_sysfs *ksm_sysfs)
 	    ksm_read_sysfs(KSM_FP("sleep_millisecs"), &ksm_sysfs->sleep_millisecs) ||
 	    ksm_read_sysfs(KSM_FP("pages_to_scan"), &ksm_sysfs->pages_to_scan) ||
 	    ksm_read_sysfs(KSM_FP("run"), &ksm_sysfs->run) ||
+	    ksm_read_sysfs(KSM_FP("smart_scan"), &ksm_sysfs->smart_scan) ||
 	    ksm_read_sysfs(KSM_FP("stable_node_chains_prune_millisecs"),
 			   &ksm_sysfs->stable_node_chains_prune_millisecs) ||
 	    ksm_read_sysfs(KSM_FP("use_zero_pages"), &ksm_sysfs->use_zero_pages))
@@ -309,6 +311,7 @@ static int ksm_restore(struct ksm_sysfs *ksm_sysfs)
 	    ksm_write_sysfs(KSM_FP("pages_to_scan"), ksm_sysfs->pages_to_scan) ||
 	    ksm_write_sysfs(KSM_FP("run"), ksm_sysfs->run) ||
 	    ksm_write_sysfs(KSM_FP("sleep_millisecs"), ksm_sysfs->sleep_millisecs) ||
+	    ksm_write_sysfs(KSM_FP("smart_scan"), ksm_sysfs->smart_scan) ||
 	    ksm_write_sysfs(KSM_FP("stable_node_chains_prune_millisecs"),
 			    ksm_sysfs->stable_node_chains_prune_millisecs) ||
 	    ksm_write_sysfs(KSM_FP("use_zero_pages"), ksm_sysfs->use_zero_pages))
@@ -846,6 +849,7 @@ int main(int argc, char *argv[])
 
 	if (ksm_write_sysfs(KSM_FP("run"), 2) ||
 	    ksm_write_sysfs(KSM_FP("sleep_millisecs"), 0) ||
+	    ksm_write_sysfs(KSM_FP("smart_scan"), 0) ||
 	    (numa_available() ? 0 :
 		ksm_write_sysfs(KSM_FP("merge_across_nodes"), 1)) ||
 	    ksm_write_sysfs(KSM_FP("pages_to_scan"), page_count))
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-24 11:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-23 18:43 [PATCH] selftests/mm: disable smart scan for ksm_tests Zenghui Yu
2026-08-24 10:33 ` David Hildenbrand (Arm)
2026-08-24 11:55   ` Zenghui Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox