mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: xu.xin16@zte.com.cn
Cc: ljs@kernel.org, akpm@linux-foundation.org, 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: Mon, 18 May 2026 11:19:11 +0200	[thread overview]
Message-ID: <7d54b6b1-1f22-483c-9629-0f4310ca97e3@kernel.org> (raw)
In-Reply-To: <202605161030201132-29L7DohlwP7mqnZJRgt@zte.com.cn>

On 5/16/26 04:30, xu.xin16@zte.com.cn wrote:
>>> --- 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?
> 
> This test runs in multi-threads, So there are not only one page from this thread but
> also many other pages which are mergeable in all other threads.

At least the test did not reveal the problem in patch #3 :)

Can't we just use a single VMA (e.g., 32 pages), fill it with pages of the same
content, let it merge, then mremap half of it, and then migrate a page etc?



-- 
Cheers,

David

  reply	other threads:[~2026-05-18  9:19 UTC|newest]

Thread overview: 19+ 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-16  9:15     ` xu.xin16
2026-05-18  8:12       ` 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-15  7:15     ` xu.xin16
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)
2026-05-16  2:30     ` xu.xin16
2026-05-18  9:19       ` David Hildenbrand (Arm) [this message]
2026-05-18 13:10         ` xu.xin16
2026-05-18 13:36           ` David Hildenbrand (Arm)
2026-05-19  3:26             ` xu.xin16
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=7d54b6b1-1f22-483c-9629-0f4310ca97e3@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

all inboxes | Powered by JetHome®