The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: [PATCH v4 5/5] ksm: add mremap selftests for ksm_rmap_walk
       [not found] <20260503205153715oK1yza2bba5lfAl3QwiPx@zte.com.cn>
@ 2026-05-13 12:10 ` David Hildenbrand (Arm)
  0 siblings, 0 replies; only message in thread
From: David Hildenbrand (Arm) @ 2026-05-13 12:10 UTC (permalink / raw)
  To: xu.xin16, ljs, akpm; +Cc: hughd, linux-mm, linux-kernel, michel

On 5/3/26 14:51, xu.xin16@zte.com.cn wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> The existing tools/testing/selftests/mm/rmap.c has already one testcase
> for ksm_rmap_walk in TEST_F(migrate, ksm), which takes use of migration
> of page from one NUMA node to another NUMA node. However, it just lacks
> the scenario of mremapped VMAs.
> 
> There are one worker process and several checker processes, and in worker,
> we add the calling of mremap() and then trigger KSM to merge pages before
> migrating, , which is specailly to test a optimization which is introduced
> by this patch ("ksm: Optimize rmap_walk_ksm by passing a suitable address
> range"). In other checker processes, we just trigger KSM to merge pages
> from each child process and check their PFN.
> 
> This test can reproduce the issue that Hugh points out at
> https://lore.kernel.org/all/02e1b8df-d568-8cbb-b8f6-46d5476d9d75@google.com/
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> ---
>  tools/testing/selftests/mm/rmap.c    | 79 ++++++++++++++++++++++++++++
>  tools/testing/selftests/mm/vm_util.c | 38 +++++++++++++
>  tools/testing/selftests/mm/vm_util.h |  2 +
>  3 files changed, 119 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/rmap.c b/tools/testing/selftests/mm/rmap.c
> index 53f2058b0ef2..fced1f6304ac 100644
> --- a/tools/testing/selftests/mm/rmap.c
> +++ b/tools/testing/selftests/mm/rmap.c
> @@ -430,4 +430,83 @@ TEST_F(migrate, ksm)
>  	propagate_children(_metadata, data);
>  }
> 
> +static void prepare_two_pages(struct global_data *data)
> +{
> +	/* Allocate exactly 2 pages for the test */
> +	data->mapsize = 2 * getpagesize();
> +	data->region = mmap(NULL, data->mapsize, PROT_READ | PROT_WRITE,
> +			    MAP_PRIVATE | MAP_ANON, -1, 0);
> +	if (data->region == MAP_FAILED)
> +		ksft_exit_fail_perror("mmap failed");
> +
> +	/* Fill both pages with identical content to encourage KSM merging */
> +	memset(data->region, 0x77, data->mapsize);
> +}
> +
> +static int mremap_merge_and_migrate(struct global_data *data)
> +{
> +	int ret, pagemap_fd;
> +	void *old_region = data->region;
> +	unsigned long page_sz = getpagesize();
> +
> +	/*
> +	 * Mremap the second page to the first page's location (FIXED).
> +	 * This effectively overwrites the first page, leaving the second page
> +	 * unmapped. The physical page originally at the second page is now
> +	 * mapped at the first page's virtual address.
> +	 */


But if there is only a single page, why should it get merged by KSM?


-- 
Cheers,

David

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-13 12:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260503205153715oK1yza2bba5lfAl3QwiPx@zte.com.cn>
2026-05-13 12:10 ` [PATCH v4 5/5] ksm: add mremap selftests for ksm_rmap_walk David Hildenbrand (Arm)

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