Message ID | 20230126202415.1682629-11-willy@infradead.org |
---|---|
State | Changes Requested |
Headers | show |
Series | Convert most of ext4 to folios | expand |
On Thu, Jan 26, 2023 at 08:23:54PM +0000, Matthew Wilcox (Oracle) wrote: > Saves a number of calls to compound_head(). Is this left over from an earlier version of this patch series? There are no changes to calls to compound_head() that I can find in this patch. > @@ -565,10 +564,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, > > /* We cannot recurse into the filesystem as the transaction is already > * started */ > - flags = memalloc_nofs_save(); > - page = grab_cache_page_write_begin(mapping, 0); > - memalloc_nofs_restore(flags); > - if (!page) { > + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, > + mapping_gfp_mask(mapping)); > + if (!folio) { > ret = -ENOMEM; > goto out; > } Is there a reason why to use FGP_NOFS as opposed to using memalloc_nofs_{save,restore}()? I thought using memalloc_nofs_save() is considered the perferred approach by mm-folks. - Ted
On Tue, Mar 14, 2023 at 06:36:21PM -0400, Theodore Ts'o wrote: > On Thu, Jan 26, 2023 at 08:23:54PM +0000, Matthew Wilcox (Oracle) wrote: > > Saves a number of calls to compound_head(). > > Is this left over from an earlier version of this patch series? There > are no changes to calls to compound_head() that I can find in this > patch. They're hidden. Here are the ones from this patch: - if (!PageUptodate(page)) { - unlock_page(page); - put_page(page); - unlock_page(page); - put_page(page); That's five. I may have missed some. > > @@ -565,10 +564,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, > > > > /* We cannot recurse into the filesystem as the transaction is already > > * started */ > > - flags = memalloc_nofs_save(); > > - page = grab_cache_page_write_begin(mapping, 0); > > - memalloc_nofs_restore(flags); > > - if (!page) { > > + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, > > + mapping_gfp_mask(mapping)); > > + if (!folio) { > > ret = -ENOMEM; > > goto out; > > } > > Is there a reason why to use FGP_NOFS as opposed to using > memalloc_nofs_{save,restore}()? > > I thought using memalloc_nofs_save() is considered the perferred > approach by mm-folks. Ideally, yes, we'd use memalloc_nofs_save(), but not like this! The way it's supposed to be used is at the point where you do something which makes the fs non-reentrant. ie when you start the transaction, you should be calling memalloc_nofs_save() and when you finish the transaction, you should be calling memalloc_nofs_restore(). That way, you don't need to adorn the entire filesystem with GFP_NOFS/FGP_NOFS/whatever, you have one place where you mark yourself non-reentrant and you're done. Once ext4 does this every time it starts a transaction, we can drop the FGP_NOFS flag usage in ext4, and once every filesystem does it, we can drop the entire flag, and that will make me happy. It's a long road, though.
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 38f6282cc012..2091077e37dc 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -535,8 +535,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, int ret, needed_blocks, no_expand; handle_t *handle = NULL; int retries = 0, sem_held = 0; - struct page *page = NULL; - unsigned int flags; + struct folio *folio = NULL; unsigned from, to; struct ext4_iloc iloc; @@ -565,10 +564,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, /* We cannot recurse into the filesystem as the transaction is already * started */ - flags = memalloc_nofs_save(); - page = grab_cache_page_write_begin(mapping, 0); - memalloc_nofs_restore(flags); - if (!page) { + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, + mapping_gfp_mask(mapping)); + if (!folio) { ret = -ENOMEM; goto out; } @@ -583,8 +581,8 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, from = 0; to = ext4_get_inline_size(inode); - if (!PageUptodate(page)) { - ret = ext4_read_inline_page(inode, page); + if (!folio_test_uptodate(folio)) { + ret = ext4_read_inline_page(inode, &folio->page); if (ret < 0) goto out; } @@ -594,21 +592,21 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, goto out; if (ext4_should_dioread_nolock(inode)) { - ret = __block_write_begin(page, from, to, + ret = __block_write_begin(&folio->page, from, to, ext4_get_block_unwritten); } else - ret = __block_write_begin(page, from, to, ext4_get_block); + ret = __block_write_begin(&folio->page, from, to, ext4_get_block); if (!ret && ext4_should_journal_data(inode)) { - ret = ext4_walk_page_buffers(handle, inode, page_buffers(page), - from, to, NULL, - do_journal_get_write_access); + ret = ext4_walk_page_buffers(handle, inode, + folio_buffers(folio), from, to, + NULL, do_journal_get_write_access); } if (ret) { - unlock_page(page); - put_page(page); - page = NULL; + folio_unlock(folio); + folio_put(folio); + folio = NULL; ext4_orphan_add(handle, inode); ext4_write_unlock_xattr(inode, &no_expand); sem_held = 0; @@ -628,12 +626,12 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry; - if (page) - block_commit_write(page, from, to); + if (folio) + block_commit_write(&folio->page, from, to); out: - if (page) { - unlock_page(page); - put_page(page); + if (folio) { + folio_unlock(folio); + folio_put(folio); } if (sem_held) ext4_write_unlock_xattr(inode, &no_expand);
Saves a number of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- fs/ext4/inline.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-)