2023-12-14 05:30:54

by Matthew Wilcox

[permalink] [raw]
Subject: [PATCH] ext4: Convert ext4_da_do_write_end() to take a folio

There's nothing page-specific happening in ext4_da_do_write_end();
it's merely used for its refcount & lock, both of which are folio
properties. Saves four calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
---
fs/ext4/inode.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 83ee4e0f46f4..216ad9bcca45 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2947,7 +2947,7 @@ static int ext4_da_should_update_i_disksize(struct folio *folio,

static int ext4_da_do_write_end(struct address_space *mapping,
loff_t pos, unsigned len, unsigned copied,
- struct page *page)
+ struct folio *folio)
{
struct inode *inode = mapping->host;
loff_t old_size = inode->i_size;
@@ -2958,12 +2958,13 @@ static int ext4_da_do_write_end(struct address_space *mapping,
* block_write_end() will mark the inode as dirty with I_DIRTY_PAGES
* flag, which all that's needed to trigger page writeback.
*/
- copied = block_write_end(NULL, mapping, pos, len, copied, page, NULL);
+ copied = block_write_end(NULL, mapping, pos, len, copied,
+ &folio->page, NULL);
new_i_size = pos + copied;

/*
- * It's important to update i_size while still holding page lock,
- * because page writeout could otherwise come in and zero beyond
+ * It's important to update i_size while still holding folio lock,
+ * because folio writeout could otherwise come in and zero beyond
* i_size.
*
* Since we are holding inode lock, we are sure i_disksize <=
@@ -2981,14 +2982,14 @@ static int ext4_da_do_write_end(struct address_space *mapping,

i_size_write(inode, new_i_size);
end = (new_i_size - 1) & (PAGE_SIZE - 1);
- if (copied && ext4_da_should_update_i_disksize(page_folio(page), end)) {
+ if (copied && ext4_da_should_update_i_disksize(folio, end)) {
ext4_update_i_disksize(inode, new_i_size);
disksize_changed = true;
}
}

- unlock_page(page);
- put_page(page);
+ folio_unlock(folio);
+ folio_put(folio);

if (old_size < pos)
pagecache_isize_extended(inode, old_size, pos);
@@ -3027,10 +3028,10 @@ static int ext4_da_write_end(struct file *file,
return ext4_write_inline_data_end(inode, pos, len, copied,
folio);

- if (unlikely(copied < len) && !PageUptodate(page))
+ if (unlikely(copied < len) && !folio_test_uptodate(folio))
copied = 0;

- return ext4_da_do_write_end(mapping, pos, len, copied, &folio->page);
+ return ext4_da_do_write_end(mapping, pos, len, copied, folio);
}

/*
--
2.42.0



2024-01-04 16:42:31

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH] ext4: Convert ext4_da_do_write_end() to take a folio

On Thu 14-12-23 05:30:35, Matthew Wilcox (Oracle) wrote:
> There's nothing page-specific happening in ext4_da_do_write_end();
> it's merely used for its refcount & lock, both of which are folio
> properties. Saves four calls to compound_head().
>
> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <[email protected]>

Honza

> ---
> fs/ext4/inode.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 83ee4e0f46f4..216ad9bcca45 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2947,7 +2947,7 @@ static int ext4_da_should_update_i_disksize(struct folio *folio,
>
> static int ext4_da_do_write_end(struct address_space *mapping,
> loff_t pos, unsigned len, unsigned copied,
> - struct page *page)
> + struct folio *folio)
> {
> struct inode *inode = mapping->host;
> loff_t old_size = inode->i_size;
> @@ -2958,12 +2958,13 @@ static int ext4_da_do_write_end(struct address_space *mapping,
> * block_write_end() will mark the inode as dirty with I_DIRTY_PAGES
> * flag, which all that's needed to trigger page writeback.
> */
> - copied = block_write_end(NULL, mapping, pos, len, copied, page, NULL);
> + copied = block_write_end(NULL, mapping, pos, len, copied,
> + &folio->page, NULL);
> new_i_size = pos + copied;
>
> /*
> - * It's important to update i_size while still holding page lock,
> - * because page writeout could otherwise come in and zero beyond
> + * It's important to update i_size while still holding folio lock,
> + * because folio writeout could otherwise come in and zero beyond
> * i_size.
> *
> * Since we are holding inode lock, we are sure i_disksize <=
> @@ -2981,14 +2982,14 @@ static int ext4_da_do_write_end(struct address_space *mapping,
>
> i_size_write(inode, new_i_size);
> end = (new_i_size - 1) & (PAGE_SIZE - 1);
> - if (copied && ext4_da_should_update_i_disksize(page_folio(page), end)) {
> + if (copied && ext4_da_should_update_i_disksize(folio, end)) {
> ext4_update_i_disksize(inode, new_i_size);
> disksize_changed = true;
> }
> }
>
> - unlock_page(page);
> - put_page(page);
> + folio_unlock(folio);
> + folio_put(folio);
>
> if (old_size < pos)
> pagecache_isize_extended(inode, old_size, pos);
> @@ -3027,10 +3028,10 @@ static int ext4_da_write_end(struct file *file,
> return ext4_write_inline_data_end(inode, pos, len, copied,
> folio);
>
> - if (unlikely(copied < len) && !PageUptodate(page))
> + if (unlikely(copied < len) && !folio_test_uptodate(folio))
> copied = 0;
>
> - return ext4_da_do_write_end(mapping, pos, len, copied, &folio->page);
> + return ext4_da_do_write_end(mapping, pos, len, copied, folio);
> }
>
> /*
> --
> 2.42.0
>
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2024-01-09 02:54:16

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH] ext4: Convert ext4_da_do_write_end() to take a folio


On Thu, 14 Dec 2023 05:30:35 +0000, Matthew Wilcox (Oracle) wrote:
> There's nothing page-specific happening in ext4_da_do_write_end();
> it's merely used for its refcount & lock, both of which are folio
> properties. Saves four calls to compound_head().
>
>

Applied, thanks!

[1/1] ext4: Convert ext4_da_do_write_end() to take a folio
commit: 05f240655f03fd7fcdbfc6129b6fb7dcc3f64e0e

Best regards,
--
Theodore Ts'o <[email protected]>