Re: [PATCH] selftests/mm: disable smart scan for ksm_tests

From: David Hildenbrand (Arm)

Date: Mon Aug 24 2026 - 06:34:27 EST


On 8/23/26 20:43, Zenghui Yu wrote:
> From: "Zenghui Yu (Huawei)" <zenghui.yu@xxxxxxxxx>
>
> 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

How did you reproduce this? Is this an actual test result?


~/linux/tools/testing/selftests/mm$ cat /sys/kernel/mm/ksm/smart_scan
1
~/linux/tools/testing/selftests/mm$ sudo ./ksm_tests -N -d
TAP version 13
1..1
pages_shared : 1
pages_sharing : 1
max_page_sharing : 256
full_scans : 1283
pages_unshared : 0
pages_volatile : 0
stable_node_chains: 0
stable_node_dups : 0
general_profit : 3968
ksm_rmap_items 2
ksm_zero_pages 0
ksm_merging_pages 2
ksm_process_profit 8064
ksm_merge_any: no
ksm_mergeable: yes
ok 1 KSM NUMA merging
# Totals: pass:1 fail:0 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

How is that supposed to happen? The sequence we have is:

numa1_map_ptr = numa_alloc_onnode(page_size, first_node);
numa2_map_ptr = numa_alloc_onnode(page_size, second_node);
...
memset(numa1_map_ptr, '*', page_size);
memset(numa2_map_ptr, '*', page_size);
...
if (ksm_merge_pages(merge_type, numa1_map_ptr, page_size, start_time, timeout) ...

KSM smart scan operates on rmap entries. rmap entries are per MM.

--
Cheers,

David