mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Qiliang Yuan <odys.yuan@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Xu Xin <xu.xin@linux.dev>,
	Chengming Zhou <chengming.zhou@linux.dev>,
	Stefan Roesch <shr@devkernel.io>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 2/2] selftests/mm: cover merging KSM pages aged by smart scan
Date: Thu, 5 Nov 2026 11:03:03 +0100	[thread overview]
Message-ID: <e6be27d9-6cf1-476e-9d8c-8e91664b95e2@kernel.org> (raw)
In-Reply-To: <20261105-bug-mm-ksm-smart-scan-align-skips-v2-2-8a9780b6844e@gmail.com>

On 11/5/26 10:36, Qiliang Yuan wrote:
> ksm_functional_tests checks merging and unmerging with ksmd's default
> settings, but nothing there exercises smart scan, which skips pages KSM
> has failed to merge for a while.
> 
> Smart scan used to time those skips per page, so two identical pages
> that became mergeable some scans apart could end up never being looked
> at in the same scan, and were never merged. "mm/ksm: align smart scan
> skips with the scan number" fixed that.
> 
> Add a case that lets sixteen unique pages age for a dozen scans, then
> makes a duplicate of each mergeable one scan apart, and expects every
> pair to be merged 32 scans later:
> 
>   kernel               failures, two boots
>   before the fix       20/20, 20/20
>   with the fix          0/20,  0/20
> 
> Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
> ---
>  tools/testing/selftests/mm/ksm_functional_tests.c | 108 +++++++++++++++++++++-
>  1 file changed, 107 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index 31c06c72203fd..71d9b3cbdb8c1 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -695,6 +695,111 @@ static void test_fork_ksm_merging_page_count(void)
>  	munmap(map, size);
>  }
>  
> +static int ksm_wait_full_scans(long nr)
> +{
> +	long start, cur;
> +
> +	start = ksm_get_full_scans();
> +	if (start < 0)
> +		return start;
> +	do {
> +		cur = ksm_get_full_scans();
> +		if (cur < 0)
> +			return cur;
> +	} while (cur < start + nr);
> +
> +	return 0;
> +}
> +

This looks a lot like the logic we have in ksm_start().

Likely that logic there should be factored out into a common helper.

> +static void test_merge_aged_pairs(void)
> +{
> +	const unsigned int pairs = 16;
> +	const unsigned long size = 2 * pairs * pagesize;
> +	char *map, old_smart_scan = '1';
> +	int smart_scan_fd;
> +	unsigned int i;
> +
> +	ksft_print_msg("[RUN] %s\n", __func__);
> +
> +	smart_scan_fd = open("/sys/kernel/mm/ksm/smart_scan", O_RDWR);
> +	if (smart_scan_fd < 0) {
> +		ksft_test_result_skip("smart_scan not supported\n");
> +		return;
> +	}
> +	if (pread(smart_scan_fd, &old_smart_scan, 1, 0) != 1 ||
> +	    pwrite(smart_scan_fd, "1", 1, 0) != 1) {
> +		ksft_test_result_fail("Enabling smart_scan failed\n");
> +		goto close_fd;
> +	}

Can we have a helper to enable/disable smart scan? Likely belongs into utils as
well.


-- 
Cheers,

David

      reply	other threads:[~2026-11-05 10:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  9:36 [PATCH v2 0/2] mm/ksm: keep smart scan from losing duplicate pages Qiliang Yuan
2026-11-05  9:36 ` [PATCH v2 1/2] mm/ksm: align smart scan skips with the scan number Qiliang Yuan
2026-11-05 10:03   ` David Hildenbrand (Arm)
2026-11-05  9:36 ` [PATCH v2 2/2] selftests/mm: cover merging KSM pages aged by smart scan Qiliang Yuan
2026-11-05 10:03   ` David Hildenbrand (Arm) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6be27d9-6cf1-476e-9d8c-8e91664b95e2@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=odys.yuan@gmail.com \
    --cc=rppt@kernel.org \
    --cc=shr@devkernel.io \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=xu.xin@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®