Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Vineet Agarwal <agarwal.vineet2006@gmail.com>,
	akpm@linux-foundation.org, ljs@kernel.org, shuah@kernel.org,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] selftests/mm: khugepaged: initialize file contents via mmap
Date: Tue, 28 Apr 2026 16:17:26 -0400	[thread overview]
Message-ID: <0FA813EA-5EFA-482F-B8BF-FE65D4169C44@nvidia.com> (raw)
In-Reply-To: <95714cec-205e-4b56-b8ff-9afaf9408020@kernel.org>

On 28 Apr 2026, at 16:07, David Hildenbrand (Arm) wrote:

> On 4/28/26 21:56, Zi Yan wrote:
>> On 28 Apr 2026, at 9:31, Vineet Agarwal wrote:
>>
>>> file_setup_area() currently allocates anonymous memory, fills it,
>>> and writes it into the backing file used for collapse testing.
>>>
>>> Instead of copying data through write(), resize the file with
>>> ftruncate(), map it directly with MAP_SHARED, and initialize the
>>> mapped area in place.
>>>
>>> This simplifies the setup path and avoids the need for explicit
>>> partial write handling.
>>>
>>> Signed-off-by: Vineet Agarwal <agarwal.vineet2006@gmail.com>
>>>
>>> v3 -> v4:
>>>   - Restore unrelated blank line removal
>>>   - Restore original close()/munmap() ordering
>>> ---
>>>  tools/testing/selftests/mm/khugepaged.c | 14 ++++++++++++--
>>>  1 file changed, 12 insertions(+), 2 deletions(-)
>>
>> This patch breaks the khugepaged test for READ_ONLY_THP_FOR_FS.
>>
>> When I ran sudo ./khugepaged all:file ~/ on ext4,
>>
>> collapse_max_ptes_none (khugepaged:file) fails.
>
> madvise() still works? Is it maybe because of dirty folios? (but that should
> also be the case on write ...)

I asked codex instead.

Basically, mmap(MMAP_SHARED) makes the written folio dirty and the folio
survives the later drop_caches. Adding msync() fixes the issue.

The patch below fixes the issue.

From fdf796e52a94b7e21614c8cfb6cc947146221d28 Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@nvidia.com>
Date: Tue, 28 Apr 2026 16:12:08 -0400
Subject: [PATCH] flush dirty folio so that drop_caches can work

Signed-off-by: Zi Yan <ziy@nvidia.com>
---
 tools/testing/selftests/mm/khugepaged.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index 87ca031cb7225..ac645d96285da 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -399,6 +399,7 @@ static void *file_setup_area_common(int nr_hpages, bool read_only)
 		exit(EXIT_FAILURE);
 	}
 	fill_memory(p, 0, size);
+	msync(p, size, MS_SYNC);
 	close(fd);
 	munmap(p, size);
 	success("OK");
-- 
2.53.0




Best Regards,
Yan, Zi

  reply	other threads:[~2026-04-28 20:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28 13:31 [PATCH v4] selftests/mm: khugepaged: initialize file contents via mmap Vineet Agarwal
2026-04-28 13:49 ` David Hildenbrand (Arm)
2026-04-28 19:56 ` Zi Yan
2026-04-28 20:07   ` David Hildenbrand (Arm)
2026-04-28 20:17     ` Zi Yan [this message]
2026-04-28 20:19       ` David Hildenbrand (Arm)
2026-04-28 20:22         ` Zi Yan
2026-04-28 20:23           ` Zi Yan
2026-04-29  6:24             ` David Hildenbrand (Arm)

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=0FA813EA-5EFA-482F-B8BF-FE65D4169C44@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=agarwal.vineet2006@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=shuah@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