From: "David Hildenbrand (Arm)" <david@kernel.org>
To: xu.xin16@zte.com.cn, ljs@kernel.org, akpm@linux-foundation.org
Cc: hughd@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, michel@lespinasse.org
Subject: Re: [PATCH v4 5/5] ksm: add mremap selftests for ksm_rmap_walk
Date: Wed, 13 May 2026 14:10:26 +0200 [thread overview]
Message-ID: <962c2a3d-0502-44b9-a115-863b513bafe2@kernel.org> (raw)
In-Reply-To: <20260503205153715oK1yza2bba5lfAl3QwiPx@zte.com.cn>
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
next prev parent reply other threads:[~2026-05-13 12:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 12:35 [PATCH v4 0/5] KSM: Optimizations for rmap_walk_ksm xu.xin16
2026-05-03 12:39 ` [PATCH v4 1/5] mm/rmap: add tracepoint for rmap_walk xu.xin16
2026-05-13 12:03 ` David Hildenbrand (Arm)
2026-05-03 12:42 ` [PATCH v4 2/5] tools/testing: add rmap walk latency benchmark for KSM, anonymous and file pages xu.xin16
2026-05-03 12:48 ` [PATCH v4 3/5] ksm: add vm_pgoff into ksm_rmap_item xu.xin16
2026-05-13 11:59 ` David Hildenbrand (Arm)
2026-05-03 12:50 ` [PATCH v4 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable address range xu.xin16
2026-05-13 12:10 ` David Hildenbrand (Arm)
2026-05-03 12:51 ` [PATCH v4 5/5] ksm: add mremap selftests for ksm_rmap_walk xu.xin16
2026-05-13 12:10 ` David Hildenbrand (Arm) [this message]
2026-05-03 14:59 ` [PATCH v4 0/5] KSM: Optimizations for rmap_walk_ksm Andrew Morton
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=962c2a3d-0502-44b9-a115-863b513bafe2@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=michel@lespinasse.org \
--cc=xu.xin16@zte.com.cn \
/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