public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] selftests/mm: khugepaged: initialize file contents via mmap
@ 2026-04-28 13:31 Vineet Agarwal
  2026-04-28 13:49 ` David Hildenbrand (Arm)
  2026-04-28 19:56 ` Zi Yan
  0 siblings, 2 replies; 9+ messages in thread
From: Vineet Agarwal @ 2026-04-28 13:31 UTC (permalink / raw)
  To: akpm, david, ljs, shuah
  Cc: linux-mm, linux-kselftest, linux-kernel, Vineet Agarwal

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(-)

diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
index 3fe7ef04ac62..6e929a484a1b 100644
--- a/tools/testing/selftests/mm/khugepaged.c
+++ b/tools/testing/selftests/mm/khugepaged.c
@@ -381,9 +381,19 @@ static void *file_setup_area(int nr_hpages)
 	}
 
 	size = nr_hpages * hpage_pmd_size;
-	p = alloc_mapping(nr_hpages);
+	if (ftruncate(fd, size)) {
+		perror("ftruncate()");
+		close(fd);
+		exit(EXIT_FAILURE);
+	}
+	p = mmap(BASE_ADDR, size, PROT_READ | PROT_WRITE,
+		MAP_SHARED, fd, 0);
+	if (p == MAP_FAILED || p != BASE_ADDR) {
+		perror("mmap()");
+		close(fd);
+		exit(EXIT_FAILURE);
+	}
 	fill_memory(p, 0, size);
-	write(fd, p, size);
 	close(fd);
 	munmap(p, size);
 	success("OK");
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-04-29  6:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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)

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