fuse: writeback clean up / refactoring
Subsystems (2)
v4 cover fuse: writeback clean up / refactoring
This patchset contains some minor clean up / refactoring for the fuse writeback code.
As a sanity check, I ran fio to check against crashes - ./libfuse/build/example/passthrough_ll -o cache=always -o writeback -o source=~/fstests ~/tmp_mount
fio --name=test --ioengine=psync --iodepth=1 --rw=randwrite --bs=1M --direct=0 --size=2G --numjobs=2 --directory=/home/user/tmp_mount
and (suggested by Miklos) fsx test -
sudo HOST_OPTIONS=fuse.config ./check -fuse generic/616 generic/616 (soak buffered fsx test) without the -U (io_uring) flag (verified this uses the fuse_writepages_fill path)
v3:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Changes from v3 -> v4:
* Merge v3's 4/9 and 5/9 into 1 patch (Josef)
* Merge v3's 7/9 and 9/9 into 1 patch
v2:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Changes from v2 -> v3:
* Drop v2 9/9 (Miklos)
* Split v2 8/9 into 2 patches (v3 8/9 and 9/9) to make review easier
* Change error pattern usage (Miklos)
v1:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Changes from v1 -> v2:
* Added patches 2 and 4-9
* Add commit message to patch 1 (Jingbo)
Joanne Koong (7):
fuse: drop unused fuse_mount arg in fuse_writepage_finish()
fuse: refactor finished writeback stats updates into helper function
fuse: update stats for pages in dropped aux writeback list
fuse: move initialization of fuse_file to fuse_writepages() instead of
in callback
fuse: convert fuse_writepages_fill() to use a folio for its tmp page
fuse: move fuse file initialization to wpa allocation time
fuse: refactor out shared logic in fuse_writepages_fill() and
fuse_writepage_locked()
fs/fuse/file.c | 167 +++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 81 deletions(-)
Signature · 1 line
2.43.5
PATCH v4 1/7 fuse: drop unused fuse_mount arg in fuse_writepage_finish()
Drop the unused "struct fuse_mount *fm" arg infuse_writepage_finish().
No functional changes added.
--- fs/fuse/file.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/fuse/file.c +3 -4
@@ -1769,8 +1769,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)kfree (wpa); } -static void fuse_writepage_finish (struct fuse_mount *fm, -struct fuse_writepage_args *wpa) +static void fuse_writepage_finish (struct fuse_writepage_args *wpa) {struct fuse_args_pages *ap = &wpa->ia.ap;struct inode *inode = wpa->inode;
@@ -1829,7 +1828,7 @@ __acquires(fi->lock) out_free: fi->writectr--;rb_erase (&wpa->writepages_entry, &fi->writepages); -fuse_writepage_finish (fm, wpa); +fuse_writepage_finish (wpa);spin_unlock (&fi->lock);/* After fuse_writepage_finish() aux request list is private */
@@ -1959,7 +1958,7 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,fuse_send_writepage (fm, next, inarg->offset + inarg->size); } fi->writectr--; -fuse_writepage_finish (fm, wpa); +fuse_writepage_finish (wpa);spin_unlock (&fi->lock);fuse_writepage_free (wpa); }
Signature · 1 line
2.43.5
PATCH v4 2/7 fuse: refactor finished writeback stats updates into helper function
In reply to Joanne KoongMove the logic for updating the bdi and page stats for a finished writeback into a separate helper function, where it can be called from both fuse_writepage_finish() and fuse_writepage_add() (in the case where there is already an auxiliary write request for the page).
No functional changes added.
Suggested by: Jingbo Xu <[email protected]>
--- fs/fuse/file.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
fs/fuse/file.c +13 -11
@@ -1769,19 +1769,25 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)kfree (wpa); } +static void fuse_writepage_finish_stat (struct inode *inode,struct page *page) +{ +struct backing_dev_info *bdi =inode_to_bdi (inode); + +dec_wb_stat (&bdi->wb,WB_WRITEBACK ); +dec_node_page_state (page,NR_WRITEBACK_TEMP ); +wb_writeout_inc (&bdi->wb); +} +static void fuse_writepage_finish (struct fuse_writepage_args *wpa) {struct fuse_args_pages *ap = &wpa->ia.ap;struct inode *inode = wpa->inode;struct fuse_inode *fi =get_fuse_inode (inode); -struct backing_dev_info *bdi =inode_to_bdi (inode);int i; -for (i =0 ; i < ap->num_pages; i++) { -dec_wb_stat (&bdi->wb,WB_WRITEBACK ); -dec_node_page_state (ap->pages[i],NR_WRITEBACK_TEMP ); -wb_writeout_inc (&bdi->wb); - } +for (i =0 ; i < ap->num_pages; i++) +fuse_writepage_finish_stat (inode, ap->pages[i]); +wake_up (&fi->page_waitq); }
@@ -2203,11 +2209,7 @@ static bool fuse_writepage_add(struct fuse_writepage_args *new_wpa,spin_unlock (&fi->lock);if (tmp) { -struct backing_dev_info *bdi =inode_to_bdi (new_wpa->inode); - -dec_wb_stat (&bdi->wb,WB_WRITEBACK ); -dec_node_page_state (new_ap->pages[0 ],NR_WRITEBACK_TEMP ); -wb_writeout_inc (&bdi->wb); +fuse_writepage_finish_stat (new_wpa->inode, new_ap->pages[0 ]);fuse_writepage_free (new_wpa); }
Signature · 1 line
2.43.5
PATCH v4 3/7 fuse: update stats for pages in dropped aux writeback list
In reply to Joanne KoongIn the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.
--- fs/fuse/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fuse/file.c +2 -1
@@ -1837,10 +1837,11 @@ __acquires(fi->lock)fuse_writepage_finish (wpa);spin_unlock (&fi->lock); -/* After fuse_writepage_finish() aux request list is private */ +/* After rb_erase() aux request list is private */ for (aux = wpa->next; aux; aux = next) { next = aux->next; aux->next =NULL ; +fuse_writepage_finish_stat (aux->inode, aux->ia.ap.pages[0 ]);fuse_writepage_free (aux); }
Signature · 1 line
2.43.5
PATCH v4 4/7 fuse: move initialization of fuse_file to fuse_writepages() instead of in callback
In reply to Joanne KoongPrior to this change, data->ff is checked and if not initialized then initialized in the fuse_writepages_fill() callback, which gets called for every dirty page in the address space mapping.
This logic is better placed in the main fuse_writepages() caller where data.ff is initialized before walking the dirty pages.
No functional changes added.
--- fs/fuse/file.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
fs/fuse/file.c +6 -12
@@ -2263,13 +2263,6 @@ static int fuse_writepages_fill(struct folio *folio,struct page *tmp_page;int err; -if (!data->ff) { - err = -EIO ; - data->ff =fuse_write_file_get (fi); -if (!data->ff) - goto out_unlock; - } -if (wpa &&fuse_writepage_need_send (fc, &folio->page, ap, data)) {fuse_writepages_send (data); data->wpa =NULL ;
@@ -2348,13 +2341,13 @@ static int fuse_writepages(struct address_space *mapping, struct writeback_control *wbc) {struct inode *inode = mapping->host; +struct fuse_inode *fi =get_fuse_inode (inode);struct fuse_conn *fc =get_fuse_conn (inode);struct fuse_fill_wb_data data;int err; - err = -EIO ;if (fuse_is_bad (inode)) - goto out; +return -EIO ;if (wbc->sync_mode ==WB_SYNC_NONE && fc->num_background >= fc->congestion_threshold)
@@ -2362,7 +2355,9 @@ static int fuse_writepages(struct address_space *mapping, data.inode = inode; data.wpa =NULL ; - data.ff =NULL ; + data.ff =fuse_write_file_get (fi); +if (!data.ff) +return -EIO ; err = -ENOMEM ; data.orig_pages = kcalloc(fc->max_pages,
@@ -2376,11 +2371,10 @@ static int fuse_writepages(struct address_space *mapping,WARN_ON (!data.wpa->ia.ap.num_pages);fuse_writepages_send (&data); } -if (data.ff) -fuse_file_put (data.ff, false);kfree (data.orig_pages); out: +fuse_file_put (data.ff, false);return err; }
Signature · 1 line
2.43.5
PATCH v4 5/7 fuse: convert fuse_writepages_fill() to use a folio for its tmp page
In reply to Joanne KoongTo pave the way for refactoring out the shared logic in fuse_writepages_fill() and fuse_writepage_locked(), this change converts the temporary page in fuse_writepages_fill() to use the folio API.
This is similar to the change in e0887e095a80 ("fuse: Convert fuse_writepage_locked to take a folio"), which converted the tmp page in fuse_writepage_locked() to use the folio API.
inc_node_page_state() is intentionally preserved here instead of converting to node_stat_add_folio() since it is updating the stat of the underlying page and to better maintain API symmetry with dec_node_page_stat() in fuse_writepage_finish_stat().
No functional changes added.
--- fs/fuse/file.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/fuse/file.c +7 -7
@@ -2260,7 +2260,7 @@ static int fuse_writepages_fill(struct folio *folio,struct inode *inode = data->inode;struct fuse_inode *fi =get_fuse_inode (inode);struct fuse_conn *fc =get_fuse_conn (inode); -struct page *tmp_page; +struct folio *tmp_folio;int err;if (wpa &&fuse_writepage_need_send (fc, &folio->page, ap, data)) {
@@ -2269,8 +2269,8 @@ static int fuse_writepages_fill(struct folio *folio, } err = -ENOMEM ; - tmp_page =alloc_page (GFP_NOFS | __GFP_HIGHMEM); -if (!tmp_page) + tmp_folio =folio_alloc (GFP_NOFS | __GFP_HIGHMEM,0 ); +if (!tmp_folio) goto out_unlock;/*
@@ -2290,7 +2290,7 @@ static int fuse_writepages_fill(struct folio *folio, err = -ENOMEM ; wpa =fuse_writepage_args_alloc ();if (!wpa) { -__free_page (tmp_page); +folio_put (tmp_folio); goto out_unlock; }fuse_writepage_add_to_bucket (fc, wpa);
@@ -2308,14 +2308,14 @@ static int fuse_writepages_fill(struct folio *folio, }folio_start_writeback (folio); -copy_highpage (tmp_page, &folio->page); - ap->pages[ap->num_pages] = tmp_page; +folio_copy (tmp_folio, folio); + ap->pages[ap->num_pages] = &tmp_folio->page; ap->descs[ap->num_pages].offset =0 ; ap->descs[ap->num_pages].length =PAGE_SIZE ; data->orig_pages[ap->num_pages] = &folio->page;inc_wb_stat (&inode_to_bdi (inode)->wb,WB_WRITEBACK ); -inc_node_page_state (tmp_page,NR_WRITEBACK_TEMP ); +inc_node_page_state (&tmp_folio->page,NR_WRITEBACK_TEMP ); err =0 ;if (data->wpa) {
Signature · 1 line
2.43.5
PATCH v4 6/7 fuse: move fuse file initialization to wpa allocation time
In reply to Joanne KoongBefore this change, wpa->ia.ff is initialized with an acquired reference on the fuse file right before it submits the writeback request. If there are auxiliary writebacks, then the initialization and reference acquisition needs to also be set before we submit the auxiliary writeback request.
To make the logic simpler and to pave the way for a subsequent refactoring of fuse_writepages_fill() and fuse_writepage_locked(), this change initializes and acquires wpa->ia.ff when the wpa is allocated.
No functional changes added.
--- fs/fuse/file.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/fuse/file.c +2 -4
@@ -1762,8 +1762,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)for (i =0 ; i < ap->num_pages; i++)__free_page (ap->pages[i]); -if (wpa->ia.ff) -fuse_file_put (wpa->ia.ff, false); +fuse_file_put (wpa->ia.ff, false);kfree (ap->pages);kfree (wpa);
@@ -1936,7 +1935,6 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args, wpa->next = next->next; next->next =NULL ; - next->ia.ff =fuse_file_get (wpa->ia.ff);tree_insert (&fi->writepages, next);/*
@@ -2155,7 +2153,6 @@ static void fuse_writepages_send(struct fuse_fill_wb_data *data)int num_pages = wpa->ia.ap.num_pages;int i; - wpa->ia.ff =fuse_file_get (data->ff);spin_lock (&fi->lock);list_add_tail (&wpa->queue_entry, &fi->queued_writes);fuse_flush_writepages (inode);
@@ -2300,6 +2297,7 @@ static int fuse_writepages_fill(struct folio *folio, ap = &wpa->ia.ap;fuse_write_args_fill (&wpa->ia, data->ff,folio_pos (folio),0 ); wpa->ia.write.in.write_flags |=FUSE_WRITE_CACHE ; + wpa->ia.ff =fuse_file_get (data->ff); wpa->next =NULL ; ap->args.in_pages = true; ap->args.end = fuse_writepage_end;
Signature · 1 line
2.43.5
PATCH v4 7/7 fuse: refactor out shared logic in fuse_writepages_fill() and fuse_writepage_locked()
In reply to Joanne KoongThis change refactors the shared logic in fuse_writepages_fill() and fuse_writepages_locked() into two separate helper functions, fuse_writepage_args_page_fill() and fuse_writepage_args_setup().
No functional changes added.
--- fs/fuse/file.c | 103 +++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 46 deletions(-)
fs/fuse/file.c +57 -46
@@ -2047,49 +2047,77 @@ static void fuse_writepage_add_to_bucket(struct fuse_conn *fc,rcu_read_unlock (); } +static void fuse_writepage_args_page_fill (struct fuse_writepage_args *wpa,struct folio *folio, +struct folio *tmp_folio,uint32_t page_index) +{ +struct inode *inode = folio->mapping->host; +struct fuse_args_pages *ap = &wpa->ia.ap; + +folio_copy (tmp_folio, folio); + + ap->pages[page_index] = &tmp_folio->page; + ap->descs[page_index].offset =0 ; + ap->descs[page_index].length =PAGE_SIZE ; + +inc_wb_stat (&inode_to_bdi (inode)->wb,WB_WRITEBACK ); +inc_node_page_state (&tmp_folio->page,NR_WRITEBACK_TEMP ); +} + +static struct fuse_writepage_args *fuse_writepage_args_setup (struct folio *folio, +struct fuse_file *ff) +{ +struct inode *inode = folio->mapping->host; +struct fuse_conn *fc =get_fuse_conn (inode); +struct fuse_writepage_args *wpa; +struct fuse_args_pages *ap; + + wpa =fuse_writepage_args_alloc (); +if (!wpa) +return NULL ; + +fuse_writepage_add_to_bucket (fc, wpa); +fuse_write_args_fill (&wpa->ia, ff,folio_pos (folio),0 ); + wpa->ia.write.in.write_flags |=FUSE_WRITE_CACHE ; + wpa->inode = inode; + wpa->ia.ff = ff; + + ap = &wpa->ia.ap; + ap->args.in_pages = true; + ap->args.end = fuse_writepage_end; + +return wpa; +} +static int fuse_writepage_locked (struct folio *folio) {struct address_space *mapping = folio->mapping;struct inode *inode = mapping->host; -struct fuse_conn *fc =get_fuse_conn (inode);struct fuse_inode *fi =get_fuse_inode (inode);struct fuse_writepage_args *wpa;struct fuse_args_pages *ap;struct folio *tmp_folio; +struct fuse_file *ff;int error = -ENOMEM ; -folio_start_writeback (folio); - - wpa =fuse_writepage_args_alloc (); -if (!wpa) - goto err; - ap = &wpa->ia.ap; - tmp_folio =folio_alloc (GFP_NOFS | __GFP_HIGHMEM,0 );if (!tmp_folio) - goto err_free; + goto err; error = -EIO ; - wpa->ia.ff =fuse_write_file_get (fi); -if (!wpa->ia.ff) + ff =fuse_write_file_get (fi); +if (!ff) goto err_nofile; -fuse_writepage_add_to_bucket (fc, wpa); -fuse_write_args_fill (&wpa->ia, wpa->ia.ff,folio_pos (folio),0 ); + wpa =fuse_writepage_args_setup (folio, ff); + error = -ENOMEM ; +if (!wpa) + goto err_writepage_args; -folio_copy (tmp_folio, folio); - wpa->ia.write.in.write_flags |=FUSE_WRITE_CACHE ; - wpa->next =NULL ; - ap->args.in_pages = true; + ap = &wpa->ia.ap; ap->num_pages =1 ; - ap->pages[0 ] = &tmp_folio->page; - ap->descs[0 ].offset =0 ; - ap->descs[0 ].length =PAGE_SIZE ; - ap->args.end = fuse_writepage_end; - wpa->inode = inode; -inc_wb_stat (&inode_to_bdi (inode)->wb,WB_WRITEBACK ); -node_stat_add_folio (tmp_folio,NR_WRITEBACK_TEMP ); +folio_start_writeback (folio); +fuse_writepage_args_page_fill (wpa, folio, tmp_folio,0 );spin_lock (&fi->lock);tree_insert (&fi->writepages, wpa);
@@ -2101,13 +2129,12 @@ static int fuse_writepage_locked(struct folio *folio)return 0 ; +err_writepage_args: +fuse_file_put (ff, false); err_nofile:folio_put (tmp_folio); -err_free: -kfree (wpa); err:mapping_set_error (folio->mapping, error); -folio_end_writeback (folio);return error; }
@@ -2285,36 +2312,20 @@ static int fuse_writepages_fill(struct folio *folio,*/ if (data->wpa ==NULL ) { err = -ENOMEM ; - wpa =fuse_writepage_args_alloc (); + wpa =fuse_writepage_args_setup (folio, data->ff);if (!wpa) {folio_put (tmp_folio); goto out_unlock; } -fuse_writepage_add_to_bucket (fc, wpa); - +fuse_file_get (wpa->ia.ff); data->max_pages =1 ; - ap = &wpa->ia.ap; -fuse_write_args_fill (&wpa->ia, data->ff,folio_pos (folio),0 ); - wpa->ia.write.in.write_flags |=FUSE_WRITE_CACHE ; - wpa->ia.ff =fuse_file_get (data->ff); - wpa->next =NULL ; - ap->args.in_pages = true; - ap->args.end = fuse_writepage_end; - ap->num_pages =0 ; - wpa->inode = inode; }folio_start_writeback (folio); -folio_copy (tmp_folio, folio); - ap->pages[ap->num_pages] = &tmp_folio->page; - ap->descs[ap->num_pages].offset =0 ; - ap->descs[ap->num_pages].length =PAGE_SIZE ; +fuse_writepage_args_page_fill (wpa, folio, tmp_folio, ap->num_pages); data->orig_pages[ap->num_pages] = &folio->page; -inc_wb_stat (&inode_to_bdi (inode)->wb,WB_WRITEBACK ); -inc_node_page_state (&tmp_folio->page,NR_WRITEBACK_TEMP ); - err =0 ;if (data->wpa) {/*
Signature · 1 line
2.43.5
Quoted 27 lines · Joanne Koong
This patchset contains some minor clean up / refactoring for the fuse writeback code.
As a sanity check, I ran fio to check against crashes - ./libfuse/build/example/passthrough_ll -o cache=always -o writeback -o source=~/fstests ~/tmp_mount
fio --name=test --ioengine=psync --iodepth=1 --rw=randwrite --bs=1M --direct=0 --size=2G --numjobs=2 --directory=/home/user/tmp_mountand (suggested by Miklos) fsx test -
sudo HOST_OPTIONS=fuse.config ./check -fuse generic/616 generic/616 (soak buffered fsx test) without the -U (io_uring) flag (verified this uses thefuse_writepages_fillpath)v3:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Changes from v3 -> v4:
* Merge v3's 4/9 and 5/9 into 1 patch (Josef)
* Merge v3's 7/9 and 9/9 into 1 patchv2:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Changes from v2 -> v3:
* Drop v2 9/9 (Miklos)
* Split v2 8/9 into 2 patches (v3 8/9 and 9/9) to make review easier
* Change error pattern usage (Miklos)
Quoted 5 lines
v1:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Changes from v1 -> v2:
* Added patches 2 and 4-9
* Add commit message to patch 1 (Jingbo)
This is good, I've based my folio conversion patches ontop of this series as well,
Thanks for this,
Josef
Quoted 10 lines · Joanne Koong
This patchset contains some minor clean up / refactoring for the fuse writeback code.
As a sanity check, I ran fio to check against crashes - ./libfuse/build/example/passthrough_ll -o cache=always -o writeback -o source=~/fstests ~/tmp_mount
fio --name=test --ioengine=psync --iodepth=1 --rw=randwrite --bs=1M --direct=0 --size=2G --numjobs=2 --directory=/home/user/tmp_mount
Quoted 4 lines
and (suggested by Miklos) fsx test -
sudo HOST_OPTIONS=fuse.config ./check -fuse generic/616 generic/616 (soak buffered fsx test) without the -U (io_uring) flag (verified this uses thefuse_writepages_fillpath)
Applied, thanks.
Miklos
Quoted 2 lines · Joanne Koong
This patchset contains some minor clean up / refactoring for the fuse writeback code.
Thanks Joanne, especially after 7/7 this looks so much better now!
I'm a bit late, reviewed-by: Bernd Schubert <[email protected]>
Quoted 2 lines · Joanne Koong
This patchset contains some minor clean up / refactoring for the fuse writeback code.
Sorry maybe it's too late and not sure if it's still needed, but anyway,
Signature · 2 lines
Thanks, Jingbo