Message ID | 20250121054054.4008049-3-willy@infradead.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [1/3] btrfs: Fix some folio-related comments | expand |
在 2025/1/21 16:10, Matthew Wilcox (Oracle) 写道: > Retrieve folios instead of pages and work on them throughout. Removes > a few calls to compound_head() and a reference to page->mapping. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > --- > fs/btrfs/free-space-cache.c | 25 +++++++++++++------------ > 1 file changed, 13 insertions(+), 12 deletions(-) > > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c > index d42b6f882f57..93b3b7c23d9b 100644 > --- a/fs/btrfs/free-space-cache.c > +++ b/fs/btrfs/free-space-cache.c > @@ -447,7 +447,7 @@ static void io_ctl_drop_pages(struct btrfs_io_ctl *io_ctl) > > static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate) > { > - struct page *page; > + struct folio *folio; > struct inode *inode = io_ctl->inode; > gfp_t mask = btrfs_alloc_write_mask(inode->i_mapping); > int i; > @@ -455,31 +455,32 @@ static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate) > for (i = 0; i < io_ctl->num_pages; i++) { > int ret; > > - page = find_or_create_page(inode->i_mapping, i, mask); > - if (!page) { > + folio = __filemap_get_folio(inode->i_mapping, i, > + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, mask); > + if (IS_ERR(folio)) { > io_ctl_drop_pages(io_ctl); > return -ENOMEM; > } > > - ret = set_folio_extent_mapped(page_folio(page)); > + ret = set_folio_extent_mapped(folio); > if (ret < 0) { > - unlock_page(page); > - put_page(page); > + folio_unlock(folio); > + folio_put(folio); > io_ctl_drop_pages(io_ctl); > return ret; > } > > - io_ctl->pages[i] = page; > - if (uptodate && !PageUptodate(page)) { > - btrfs_read_folio(NULL, page_folio(page)); > - lock_page(page); > - if (page->mapping != inode->i_mapping) { > + io_ctl->pages[i] = &folio->page; > + if (uptodate && !folio_test_uptodate(folio)) { > + btrfs_read_folio(NULL, folio); > + folio_lock(folio); > + if (folio->mapping != inode->i_mapping) { > btrfs_err(BTRFS_I(inode)->root->fs_info, > "free space cache page truncated"); > io_ctl_drop_pages(io_ctl); > return -EIO; > } > - if (!PageUptodate(page)) { > + if (!folio_test_uptodate(folio)) { > btrfs_err(BTRFS_I(inode)->root->fs_info, > "error reading free space cache"); > io_ctl_drop_pages(io_ctl);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index d42b6f882f57..93b3b7c23d9b 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -447,7 +447,7 @@ static void io_ctl_drop_pages(struct btrfs_io_ctl *io_ctl) static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate) { - struct page *page; + struct folio *folio; struct inode *inode = io_ctl->inode; gfp_t mask = btrfs_alloc_write_mask(inode->i_mapping); int i; @@ -455,31 +455,32 @@ static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate) for (i = 0; i < io_ctl->num_pages; i++) { int ret; - page = find_or_create_page(inode->i_mapping, i, mask); - if (!page) { + folio = __filemap_get_folio(inode->i_mapping, i, + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, mask); + if (IS_ERR(folio)) { io_ctl_drop_pages(io_ctl); return -ENOMEM; } - ret = set_folio_extent_mapped(page_folio(page)); + ret = set_folio_extent_mapped(folio); if (ret < 0) { - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); io_ctl_drop_pages(io_ctl); return ret; } - io_ctl->pages[i] = page; - if (uptodate && !PageUptodate(page)) { - btrfs_read_folio(NULL, page_folio(page)); - lock_page(page); - if (page->mapping != inode->i_mapping) { + io_ctl->pages[i] = &folio->page; + if (uptodate && !folio_test_uptodate(folio)) { + btrfs_read_folio(NULL, folio); + folio_lock(folio); + if (folio->mapping != inode->i_mapping) { btrfs_err(BTRFS_I(inode)->root->fs_info, "free space cache page truncated"); io_ctl_drop_pages(io_ctl); return -EIO; } - if (!PageUptodate(page)) { + if (!folio_test_uptodate(folio)) { btrfs_err(BTRFS_I(inode)->root->fs_info, "error reading free space cache"); io_ctl_drop_pages(io_ctl);
Retrieve folios instead of pages and work on them throughout. Removes a few calls to compound_head() and a reference to page->mapping. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- fs/btrfs/free-space-cache.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)