mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE

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: 34488399fa ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
Reported-by: Chris Mason <[email protected]>
Cc: [email protected]
Reviewed-by: Lorenzo Stoakes (ARM) <[email protected]>
Acked-by: Hugh Dickins <[email protected]>
Acked-by: Zi Yan <[email protected]>
Reviewed-by: Zach O'Keefe <[email protected]>
Reviewed-by: SJ Park <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
Reviewed-by: Lance Yang <[email protected]>
Reviewed-by: Kiryl Shutsemau (Meta) <[email protected]>
Link: https://patch.msgid.link/[email protected]
Reviewed-by: Pedro Falcato <[email protected]>
Signed-off-by: David Hildenbrand (Arm) <[email protected]>
This commit is contained in:
David Hildenbrand (Arm)
2026-11-06 14:55:27 +01:00
parent f66469d990
commit 043a2260b9
+6
View File
@@ -1888,6 +1888,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: