From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-fsdevel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Subject: [PATCH 11/23] f2fs: Convert f2fs_write_begin() to use a folio
Date: Wed, 17 Jul 2024 16:47:01 +0100 [thread overview]
Message-ID: <20240717154716.237943-12-willy@infradead.org> (raw)
In-Reply-To: <20240717154716.237943-1-willy@infradead.org>
Fetch a folio from the page cache instead of a page and use it
throughout. We still have to convert back to a page for calling
internal f2fs functions, but hopefully they will be converted soon.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/f2fs/data.c | 66 ++++++++++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 31 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 58ac23e124a5..9a45f9fb8a64 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3556,8 +3556,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
{
struct inode *inode = mapping->host;
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
- struct page *page = NULL;
- pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT;
+ struct folio *folio;
+ pgoff_t index = pos >> PAGE_SHIFT;
bool need_balance = false;
bool use_cow = false;
block_t blkaddr = NULL_ADDR;
@@ -3573,7 +3573,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
/*
* We should check this at this moment to avoid deadlock on inode page
* and #0 page. The locking rule for inline_data conversion should be:
- * lock_page(page #0) -> lock_page(inode_page)
+ * folio_lock(folio #0) -> folio_lock(inode_page)
*/
if (index != 0) {
err = f2fs_convert_inline_inode(inode);
@@ -3603,81 +3603,85 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
repeat:
/*
- * Do not use grab_cache_page_write_begin() to avoid deadlock due to
- * wait_for_stable_page. Will wait that below with our IO control.
+ * Do not use FGP_STABLE to avoid deadlock.
+ * Will wait that below with our IO control.
*/
- page = f2fs_pagecache_get_page(mapping, index,
+ folio = __filemap_get_folio(mapping, index,
FGP_LOCK | FGP_WRITE | FGP_CREAT, GFP_NOFS);
- if (!page) {
- err = -ENOMEM;
+ if (IS_ERR(folio)) {
+ err = PTR_ERR(folio);
goto fail;
}
/* TODO: cluster can be compressed due to race with .writepage */
- *pagep = page;
+ *pagep = &folio->page;
if (f2fs_is_atomic_file(inode))
- err = prepare_atomic_write_begin(sbi, page, pos, len,
+ err = prepare_atomic_write_begin(sbi, &folio->page, pos, len,
&blkaddr, &need_balance, &use_cow);
else
- err = prepare_write_begin(sbi, page, pos, len,
+ err = prepare_write_begin(sbi, &folio->page, pos, len,
&blkaddr, &need_balance);
if (err)
- goto fail;
+ goto put_folio;
if (need_balance && !IS_NOQUOTA(inode) &&
has_not_enough_free_secs(sbi, 0, 0)) {
- unlock_page(page);
+ folio_unlock(folio);
f2fs_balance_fs(sbi, true);
- lock_page(page);
- if (page->mapping != mapping) {
- /* The page got truncated from under us */
- f2fs_put_page(page, 1);
+ folio_lock(folio);
+ if (folio->mapping != mapping) {
+ /* The folio got truncated from under us */
+ folio_unlock(folio);
+ folio_put(folio);
goto repeat;
}
}
- f2fs_wait_on_page_writeback(page, DATA, false, true);
+ f2fs_wait_on_page_writeback(&folio->page, DATA, false, true);
- if (len == PAGE_SIZE || PageUptodate(page))
+ if (len == folio_size(folio) || folio_test_uptodate(folio))
return 0;
if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode) &&
!f2fs_verity_in_progress(inode)) {
- zero_user_segment(page, len, PAGE_SIZE);
+ folio_zero_segment(folio, len, PAGE_SIZE);
return 0;
}
if (blkaddr == NEW_ADDR) {
- zero_user_segment(page, 0, PAGE_SIZE);
- SetPageUptodate(page);
+ folio_zero_segment(folio, 0, folio_size(folio));
+ folio_mark_uptodate(folio);
} else {
if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
DATA_GENERIC_ENHANCE_READ)) {
err = -EFSCORRUPTED;
- goto fail;
+ goto put_folio;
}
err = f2fs_submit_page_read(use_cow ?
- F2FS_I(inode)->cow_inode : inode, page,
+ F2FS_I(inode)->cow_inode : inode, &folio->page,
blkaddr, 0, true);
if (err)
- goto fail;
+ goto put_folio;
- lock_page(page);
- if (unlikely(page->mapping != mapping)) {
- f2fs_put_page(page, 1);
+ folio_lock(folio);
+ if (unlikely(folio->mapping != mapping)) {
+ folio_unlock(folio);
+ folio_put(folio);
goto repeat;
}
- if (unlikely(!PageUptodate(page))) {
+ if (unlikely(!folio_test_uptodate(folio))) {
err = -EIO;
- goto fail;
+ goto put_folio;
}
}
return 0;
+put_folio:
+ folio_unlock(folio);
+ folio_put(folio);
fail:
- f2fs_put_page(page, 1);
f2fs_write_failed(inode, pos + len);
return err;
}
--
2.43.0
next prev parent reply other threads:[~2024-07-17 15:47 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-17 15:46 [PATCH 00/23] Convert write_begin / write_end to take a folio Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 01/23] reiserfs: Convert grab_tail_page() to use " Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 02/23] reiserfs: Convert reiserfs_write_begin() " Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 03/23] block: Use a folio in blkdev_write_end() Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 04/23] buffer: Use a folio in generic_write_end() Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 05/23] nilfs2: Use a folio in nilfs_recover_dsync_blocks() Matthew Wilcox (Oracle)
2024-07-18 17:14 ` Ryusuke Konishi
2024-07-17 15:46 ` [PATCH 06/23] ntfs3: Remove reset_log_file() Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 07/23] buffer: Convert block_write_end() to take a folio Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 08/23] ecryptfs: Convert ecryptfs_write_end() to use " Matthew Wilcox (Oracle)
2024-07-17 15:46 ` [PATCH 09/23] ecryptfs: Use a folio in ecryptfs_write_begin() Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 10/23] f2fs: Convert f2fs_write_end() to use a folio Matthew Wilcox (Oracle)
2024-07-17 15:47 ` Matthew Wilcox (Oracle) [this message]
2024-07-17 15:47 ` [PATCH 12/23] fuse: Convert fuse_write_end() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 13/23] fuse: Convert fuse_write_begin() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 14/23] hostfs: Convert hostfs_write_end() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 15/23] jffs2: Convert jffs2_write_end() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 16/23] jffs2: Convert jffs2_write_begin() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 17/23] orangefs: Convert orangefs_write_end() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 18/23] orangefs: Convert orangefs_write_begin() " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 19/23] vboxsf: Use a folio in vboxsf_write_end() Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 20/23] fs: Convert aops->write_end to take a folio Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 21/23] fs: Convert aops->write_begin " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 22/23] ocfs2: Convert ocfs2_write_zero_page to use " Matthew Wilcox (Oracle)
2024-07-17 15:47 ` [PATCH 23/23] buffer: Convert __block_write_begin() to take " Matthew Wilcox (Oracle)
2024-07-18 15:24 ` [PATCH 00/23] Convert write_begin / write_end " Josef Bacik
2024-07-23 7:49 ` Christian Brauner
2024-07-23 13:20 ` Matthew Wilcox
2024-07-23 13:41 ` Christian Brauner
2024-07-23 22:54 ` Matthew Wilcox
2024-07-30 14:23 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240717154716.237943-12-willy@infradead.org \
--to=willy@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).