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 <[email protected]> >>> >>> 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 <[email protected]> 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 <[email protected]> --- 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

