f2fs: Convert truncate_partial_data_page() to use a folio

Retrieve a folio from the page cache and use it throughout.
Saves five hidden calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Matthew Wilcox (Oracle) 2025-02-18 05:51:58 +00:00 committed by Jaegeuk Kim
parent 6d1ba45c8d
commit ab907aa2a2

View File

@ -707,31 +707,33 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,
loff_t offset = from & (PAGE_SIZE - 1);
pgoff_t index = from >> PAGE_SHIFT;
struct address_space *mapping = inode->i_mapping;
struct page *page;
struct folio *folio;
if (!offset && !cache_only)
return 0;
if (cache_only) {
page = find_lock_page(mapping, index);
if (page && PageUptodate(page))
folio = filemap_lock_folio(mapping, index);
if (IS_ERR(folio))
return 0;
if (folio_test_uptodate(folio))
goto truncate_out;
f2fs_put_page(page, 1);
f2fs_folio_put(folio, true);
return 0;
}
page = f2fs_get_lock_data_page(inode, index, true);
if (IS_ERR(page))
return PTR_ERR(page) == -ENOENT ? 0 : PTR_ERR(page);
folio = f2fs_get_lock_data_folio(inode, index, true);
if (IS_ERR(folio))
return PTR_ERR(folio) == -ENOENT ? 0 : PTR_ERR(folio);
truncate_out:
f2fs_wait_on_page_writeback(page, DATA, true, true);
zero_user(page, offset, PAGE_SIZE - offset);
f2fs_folio_wait_writeback(folio, DATA, true, true);
folio_zero_segment(folio, offset, folio_size(folio));
/* An encrypted inode should have a key and truncate the last page. */
f2fs_bug_on(F2FS_I_SB(inode), cache_only && IS_ENCRYPTED(inode));
if (!cache_only)
set_page_dirty(page);
f2fs_put_page(page, 1);
folio_mark_dirty(folio);
f2fs_folio_put(folio, true);
return 0;
}