Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
@ 2026-11-05 18:16 David Hildenbrand (Arm)
  2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-05 18:16 UTC (permalink / raw)
  To: Andrew Morton, Zi Yan, Baolin Wang, Hugh Dickins, Liam R. Howlett,
	Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
	Usama Arif, Kiryl Shutsemau, Zach O'Keefe
  Cc: linux-mm, linux-kernel, Chris Mason, stable,
	David Hildenbrand (Arm)

madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
uptodate. For example, shmem fallocate() can put such folios into the
page cache.

collapse_file() already refuses to proceed with folios that are not
uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
such folios, leaving handling to the page faults.

Note that collapse_file() effectively clears shmem folios through
shmem_get_folio(); let's keep this fix simple and simply let the page
fault path deal with that.

Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
Reported-by: Chris Mason <mason@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
Once reviewed, I will pick this up in a timely manner.
---
 mm/khugepaged.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 8d9f05a39afb3..db135b3c44ef1 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1900,6 +1900,12 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
 		goto drop_folio;
 	}
 
+	/* Leave any uninitialized folios to the page fault path. */
+	if (!folio_test_uptodate(folio)) {
+		result = SCAN_FAIL;
+		goto drop_folio;
+	}
+
 	result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
 	switch (result) {
 	case SCAN_SUCCEED:

---

base-commit: f44fd601f72e09e44c667b9234c9cd469856679c

change-id: 20261105-set_huge_pmd_uptodate-9b9820307f30

--

Cheers,

David



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

end of thread, other threads:[~2026-11-05 21:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 18:16 [PATCH] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE David Hildenbrand (Arm)
2026-11-05 19:34 ` Lorenzo Stoakes (ARM)
2026-11-05 19:58 ` Hugh Dickins
2026-11-05 20:09 ` Zi Yan
2026-11-05 21:24   ` Zach O'Keefe

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