diff mbox series

[RFC] pagecache_isize_extended

Message ID Zaf9TgExOXsOYvW4@casper.infradead.org (mailing list archive)
State New, archived
Headers show
Series [RFC] pagecache_isize_extended | expand

Commit Message

Matthew Wilcox Jan. 17, 2024, 4:16 p.m. UTC
I hadn't looked at pagecache_isize_extended() before, and I'm not
entirely sure it's doing the right thing for large folios.  Usually
we decline to create folios which extend past EOF [1], and we try to split
folios on truncate.  But folio splitting can fail, and I think we might
run into problems with a store to a folio which straddles i_size.

Do we have any xfstests which cover this?  I'm not quite sure how to
write such a test.

[1] or at least EOF rounded up to PAGE_SIZE
diff mbox series

Patch

diff --git a/mm/truncate.c b/mm/truncate.c
index 725b150e47ac..3025c579db52 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -781,8 +781,7 @@  void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 {
 	int bsize = i_blocksize(inode);
 	loff_t rounded_from;
-	struct page *page;
-	pgoff_t index;
+	struct folio *folio;
 
 	WARN_ON(to > inode->i_size);
 
@@ -793,19 +792,18 @@  void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 	if (to <= rounded_from || !(rounded_from & (PAGE_SIZE - 1)))
 		return;
 
-	index = from >> PAGE_SHIFT;
-	page = find_lock_page(inode->i_mapping, index);
-	/* Page not cached? Nothing to do */
-	if (!page)
+	folio = filemap_lock_folio(inode->i_mapping, from / PAGE_SIZE);
+	/* Folio not cached? Nothing to do */
+	if (!folio)
 		return;
 	/*
-	 * See clear_page_dirty_for_io() for details why set_page_dirty()
+	 * See folio_clear_dirty_for_io() for details why folio_mark_dirty()
 	 * is needed.
 	 */
-	if (page_mkclean(page))
-		set_page_dirty(page);
-	unlock_page(page);
-	put_page(page);
+	if (folio_mkclean(folio))
+		folio_mark_dirty(folio);
+	folio_unlock(folio);
+	folio_put(folio);
 }
 EXPORT_SYMBOL(pagecache_isize_extended);