diff --git a/mm/shmem.c b/mm/shmem.c index 806741bbe4a6..f7c08e169e42 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1024,7 +1024,24 @@ whole_folios: } VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); - truncate_inode_folio(mapping, folio); + + if (!folio_test_large(folio)) { + truncate_inode_folio(mapping, folio); + } else if (truncate_inode_partial_folio(folio, lstart, lend)) { + /* + * If we split a page, reset the loop so + * that we pick up the new sub pages. + * Otherwise the THP was entirely + * dropped or the target range was + * zeroed, so just continue the loop as + * is. + */ + if (!folio_test_large(folio)) { + folio_unlock(folio); + index = start; + break; + } + } } index = folio->index + folio_nr_pages(folio) - 1; folio_unlock(folio);