Commit 03fbf77a authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by David Sterba

btrfs: convert defrag_prepare_one_page() to use a folio

Use a folio throughout defrag_prepare_one_page() to remove dozens of
hidden calls to compound_head().  There is no support here for large
folios; indeed, turn the existing check for PageCompound into a check
for large folios.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent dfba9f47
...@@ -868,13 +868,14 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i ...@@ -868,13 +868,14 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i
u64 page_start = (u64)index << PAGE_SHIFT; u64 page_start = (u64)index << PAGE_SHIFT;
u64 page_end = page_start + PAGE_SIZE - 1; u64 page_end = page_start + PAGE_SIZE - 1;
struct extent_state *cached_state = NULL; struct extent_state *cached_state = NULL;
struct page *page; struct folio *folio;
int ret; int ret;
again: again:
page = find_or_create_page(mapping, index, mask); folio = __filemap_get_folio(mapping, index,
if (!page) FGP_LOCK | FGP_ACCESSED | FGP_CREAT, mask);
return ERR_PTR(-ENOMEM); if (IS_ERR(folio))
return &folio->page;
/* /*
* Since we can defragment files opened read-only, we can encounter * Since we can defragment files opened read-only, we can encounter
...@@ -884,16 +885,16 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i ...@@ -884,16 +885,16 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i
* executables that explicitly enable them, so this isn't very * executables that explicitly enable them, so this isn't very
* restrictive. * restrictive.
*/ */
if (PageCompound(page)) { if (folio_test_large(folio)) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return ERR_PTR(-ETXTBSY); return ERR_PTR(-ETXTBSY);
} }
ret = set_page_extent_mapped(page); ret = set_folio_extent_mapped(folio);
if (ret < 0) { if (ret < 0) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -908,17 +909,17 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i ...@@ -908,17 +909,17 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i
if (!ordered) if (!ordered)
break; break;
unlock_page(page); folio_unlock(folio);
btrfs_start_ordered_extent(ordered); btrfs_start_ordered_extent(ordered);
btrfs_put_ordered_extent(ordered); btrfs_put_ordered_extent(ordered);
lock_page(page); folio_lock(folio);
/* /*
* We unlocked the page above, so we need check if it was * We unlocked the folio above, so we need check if it was
* released or not. * released or not.
*/ */
if (page->mapping != mapping || !PagePrivate(page)) { if (folio->mapping != mapping || !folio->private) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
goto again; goto again;
} }
} }
...@@ -927,21 +928,21 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i ...@@ -927,21 +928,21 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, pgoff_t i
* Now the page range has no ordered extent any more. Read the page to * Now the page range has no ordered extent any more. Read the page to
* make it uptodate. * make it uptodate.
*/ */
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
btrfs_read_folio(NULL, page_folio(page)); btrfs_read_folio(NULL, folio);
lock_page(page); folio_lock(folio);
if (page->mapping != mapping || !PagePrivate(page)) { if (folio->mapping != mapping || !folio->private) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
goto again; goto again;
} }
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
} }
return page; return &folio->page;
} }
struct defrag_target_range { struct defrag_target_range {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment