mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Xu Xin (vivo)" <xu.xin@linux.dev>
To: Qiliang Yuan <odys.yuan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	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>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 4/5] selftests/mm: move waiting for KSM full scans into a helper
Date: Mon, 9 Nov 2026 10:32:45 +0800	[thread overview]
Message-ID: <avEwza7YqonhwgO+@dgvxl46587.localhost.localdomain> (raw)
In-Reply-To: <20261108-bug-mm-ksm-smart-scan-align-skips-v4-4-86be8fe77e7a@gmail.com>

On Sun, Nov 08, 2026 at 08:22:53PM -0500, Qiliang Yuan wrote:
> ksm_start() enables ksmd and then polls full_scans until two more full
> scans have completed, so that any merging that can happen has happened.
> 
> There is no helper to wait for a number of full scans while ksmd is
> already running, so a test that needs one has to copy that loop.
> 
> Move the loop into ksm_wait_full_scans() and make ksm_start() call it
> after enabling ksmd. The count is now read after ksmd starts rather than
> before, which can only make ksm_start() wait longer.
> 
> Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
> Tested-by: Andrew Morton <akpm@linux-foundation.org>
> Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>

Reviewed-by: Xu Xin (vivo) <xu.xin@linux.dev>

> ---
>  tools/testing/selftests/mm/vm_util.c | 31 ++++++++++++++++++-------------
>  tools/testing/selftests/mm/vm_util.h |  1 +
>  2 files changed, 19 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index caea045fa7d46..8184691211acc 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -992,35 +992,40 @@ int ksm_use_zero_pages(void)
>  	return ret == 1 ? 0 : -EIO;
>  }
>  
> +int ksm_wait_full_scans(long nr)
> +{
> +	long start_scans, end_scans;
> +
> +	start_scans = ksm_get_full_scans();
> +	if (start_scans < 0)
> +		return start_scans;
> +	do {
> +		end_scans = ksm_get_full_scans();
> +		if (end_scans < 0)
> +			return end_scans;
> +	} while (end_scans < start_scans + nr);
> +
> +	return 0;
> +}
> +
>  int ksm_start(void)
>  {
>  	int ksm_fd;
>  	ssize_t ret;
> -	long start_scans, end_scans;
>  
>  	ksm_fd = open("/sys/kernel/mm/ksm/run", O_RDWR);
>  	if (ksm_fd < 0)
>  		return -errno;
>  
> -	/* Wait for two full scans such that any possible merging happened. */
> -	start_scans = ksm_get_full_scans();
> -	if (start_scans < 0) {
> -		close(ksm_fd);
> -		return start_scans;
> -	}
>  	ret = write(ksm_fd, "1", 1);
>  	close(ksm_fd);
>  	if (ret < 0)
>  		return -errno;
>  	if (ret != 1)
>  		return -EIO;
> -	do {
> -		end_scans = ksm_get_full_scans();
> -		if (end_scans < 0)
> -			return end_scans;
> -	} while (end_scans < start_scans + 2);
>  
> -	return 0;
> +	/* Wait for two full scans such that any possible merging happened. */
> +	return ksm_wait_full_scans(2);
>  }
>  
>  int ksm_stop(void)
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index b5d59729d4327..7e00030077d2f 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -162,6 +162,7 @@ void *sys_mremap(void *old_address, unsigned long old_size,
>  long ksm_get_self_zero_pages(void);
>  long ksm_get_self_merging_pages(void);
>  long ksm_get_full_scans(void);
> +int ksm_wait_full_scans(long nr);
>  int ksm_use_zero_pages(void);
>  int ksm_start(void);
>  int ksm_stop(void);
> 
> -- 
> 2.43.0
> 

  reply	other threads:[~2026-11-09  2:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  1:22 [PATCH v4 0/5] mm/ksm: keep smart scan from losing duplicate pages Qiliang Yuan
2026-11-09  1:22 ` [PATCH v4 1/5] mm/ksm: align smart scan skips with the scan number Qiliang Yuan
2026-11-09  1:22 ` [PATCH v4 2/5] docs/mm: ksm: describe how smart scan picks the scans to skip Qiliang Yuan
2026-11-09  2:12   ` Xu Xin (vivo)
2026-11-09  1:22 ` [PATCH v4 3/5] selftests/mm: fail KSM helpers on short reads and writes Qiliang Yuan
2026-11-09  2:29   ` Xu Xin (vivo)
2026-11-09  1:22 ` [PATCH v4 4/5] selftests/mm: move waiting for KSM full scans into a helper Qiliang Yuan
2026-11-09  2:32   ` Xu Xin (vivo) [this message]
2026-11-09  1:22 ` [PATCH v4 5/5] selftests/mm: cover merging KSM pages aged by smart scan Qiliang Yuan
2026-11-09  2:34   ` Xu Xin (vivo)

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=avEwza7YqonhwgO+@dgvxl46587.localhost.localdomain \
    --to=xu.xin@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-doc@vger.kernel.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=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=shr@devkernel.io \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /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®