use bio_complete_in_task for iomap error reporting
Subsystems (2)
Hi all,
this series replaces three pieces of code to queue up I/O completions in user context for error reporting with the relatively new block layer bio_complete_in_task() mechanism.
Diffstat:
bio.c | 46 ++-------------------------------------------- direct-io.c | 19 +------------------ ioend.c | 48 ++---------------------------------------------- 3 files changed, 5 insertions(+), 108 deletions(-)
PATCH 1/3 iomap: use bio_complete_in_task for buffered read failures
Use bio_complete_in_task to defer the bio completion handler to task context instead of the homegrown deferral.
--- fs/iomap/bio.c | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-)
fs/iomap/bio.c +2 -44
@@ -9,9 +9,6 @@#include "internal.h" #include "trace.h" -static DEFINE_SPINLOCK (failed_read_lock); -static struct bio_list failed_read_list =BIO_EMPTY_LIST ; -static u32 __iomap_read_end_io (struct bio *bio,int error) {struct folio_iter fi;
@@ -27,50 +24,11 @@ static u32 __iomap_read_end_io(struct bio *bio, int error)return folio_count; } -static void -iomap_fail_reads ( -struct work_struct *work) -{ -struct bio *bio; -struct bio_list tmp =BIO_EMPTY_LIST ; -unsigned long flags; - -spin_lock_irqsave (&failed_read_lock, flags); -bio_list_merge_init (&tmp, &failed_read_list); -spin_unlock_irqrestore (&failed_read_lock, flags); - -while ((bio =bio_list_pop (&tmp)) !=NULL ) { -__iomap_read_end_io (bio,blk_status_to_errno (bio->bi_status)); -cond_resched (); - } -} - -static DECLARE_WORK(failed_read_work, iomap_fail_reads); - -static void iomap_fail_buffered_read (struct bio *bio) -{ -unsigned long flags; - -/* -* Bounce I/O errors to a workqueue to avoid nested i_lock acquisitions -* in the fserror code. The caller no longer owns the bio reference -* after the spinlock drops. -*/ -spin_lock_irqsave (&failed_read_lock, flags); -if (bio_list_empty (&failed_read_list)) -WARN_ON_ONCE (!schedule_work (&failed_read_work)); -bio_list_add (&failed_read_list, bio); -spin_unlock_irqrestore (&failed_read_lock, flags); -} -static void iomap_read_end_io (struct bio *bio) { -if (bio->bi_status) { -iomap_fail_buffered_read (bio); +if (bio->bi_status &&bio_complete_in_task (bio))return ; - } - -__iomap_read_end_io (bio,0 ); +__iomap_read_end_io (bio,blk_status_to_errno (bio->bi_status)); }u32 iomap_finish_ioend_buffered_read (struct iomap_ioend *ioend)
Signature · 1 line
2.53.0
Re: [PATCH 1/3] iomap: use bio_complete_in_task for buffered read failures
Quoted 57 lines · Christoph Hellwig
Use
bio_complete_in_taskto defer the bio completion handler to task context instead of the homegrown deferral.Signed-off-by Christoph Hellwig <[email protected]>--- fs/iomap/bio.c | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-)fs/iomap/bio.c +0
-34@@ -9,9 +9,6 @@#include "internal.h" #include "trace.h" -static DEFINE_SPINLOCK (failed_read_lock); -static struct bio_list failed_read_list =BIO_EMPTY_LIST ; -static u32 __iomap_read_end_io (struct bio *bio,int error) {struct folio_iter fi;@@ -27,50 +24,11 @@ static u32 __iomap_read_end_io(struct bio *bio, int error)return folio_count; } -static void -iomap_fail_reads ( -struct work_struct *work) -{ -struct bio *bio; -struct bio_list tmp =BIO_EMPTY_LIST ; -unsigned long flags; - -spin_lock_irqsave (&failed_read_lock, flags); -bio_list_merge_init (&tmp, &failed_read_list); -spin_unlock_irqrestore (&failed_read_lock, flags); - -while ((bio =bio_list_pop (&tmp)) !=NULL ) { -__iomap_read_end_io (bio,blk_status_to_errno (bio->bi_status)); -cond_resched (); - } -} - -static DECLARE_WORK(failed_read_work, iomap_fail_reads); - -static void iomap_fail_buffered_read (struct bio *bio) -{ -unsigned long flags; - -/* -* Bounce I/O errors to a workqueue to avoid nested i_lock acquisitions -* in the fserror code. The caller no longer owns the bio reference -* after the spinlock drops. -*/ -spin_lock_irqsave (&failed_read_lock, flags); -if (bio_list_empty (&failed_read_list))
fs/iomap/bio.c static u32 __iomap_read_end_io(struct bio *bio, int error) · line 29
Quoted 10 lines
fs/iomap/bio.c +1
-7-WARN_ON_ONCE (!schedule_work (&failed_read_work)); -bio_list_add (&failed_read_list, bio); -spin_unlock_irqrestore (&failed_read_lock, flags); -} -static void iomap_read_end_io (struct bio *bio) { -if (bio->bi_status) { -iomap_fail_buffered_read (bio); +if (bio->bi_status &&bio_complete_in_task (bio))
Hmm.
If bio failed, we call bio_complete_in_task to do something with the bio. If the bio wasn't flagged COMPLETE_IN_TASK and we're in atomic context, then __bio_complete_in_task will queue the bio to a per-cpu completion batch, (maybe) schedule a worker to deal with the batch, and we're done.
If the bio was already a COMPLETE_IN_TASK bio or we're not in atomic context, the function returns false and we fall through to the __iomap_read_end_io call below.
That looks like a correct conversion of the iomap_fail_buffered_read code, with only the slight change that we're using a per-cpu batch instead of a single static list. Right?
If yes, then
--D
Quoted 11 lines
fs/iomap/bio.c +1
-3return ; - } - -__iomap_read_end_io (bio,0 ); +__iomap_read_end_io (bio,blk_status_to_errno (bio->bi_status)); }u32 iomap_finish_ioend_buffered_read (struct iomap_ioend *ioend)Signature · 1 line
2.53.0
Re: [PATCH 1/3] iomap: use bio_complete_in_task for buffered read failures
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Use
bio_complete_in_taskto defer the bio completion handler to task context instead of the homegrown deferral.Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me
Signature · 1 line
- Andrey
PATCH 2/3 iomap: use bio_complete_in_task for buffered write failures
In reply to Christoph HellwigUse bio_complete_in_task to defer the bio completion handler to task context instead of the homegrown deferral.
--- fs/iomap/ioend.c | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-)
fs/iomap/ioend.c +2 -46
@@ -74,57 +74,13 @@ static u32 iomap_finish_ioend_buffered_write(struct iomap_ioend *ioend)return folio_count; } -static DEFINE_SPINLOCK (failed_ioend_lock); -static LIST_HEAD (failed_ioend_list); - -static void -iomap_fail_ioends ( -struct work_struct *work) -{ -struct iomap_ioend *ioend; -struct list_head tmp; -unsigned long flags; - -spin_lock_irqsave (&failed_ioend_lock, flags); -list_replace_init (&failed_ioend_list, &tmp); -spin_unlock_irqrestore (&failed_ioend_lock, flags); - - while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend, - io_list))) { -list_del_init (&ioend->io_list); -iomap_finish_ioend_buffered_write (ioend); -cond_resched (); - } -} - -static DECLARE_WORK(failed_ioend_work, iomap_fail_ioends); - -static void iomap_fail_ioend_buffered (struct iomap_ioend *ioend) -{ -unsigned long flags; - -/* -* Bounce I/O errors to a workqueue to avoid nested i_lock acquisitions -* in the fserror code. The caller no longer owns the ioend reference -* after the spinlock drops. -*/ -spin_lock_irqsave (&failed_ioend_lock, flags); -if (list_empty (&failed_ioend_list)) -WARN_ON_ONCE (!schedule_work (&failed_ioend_work)); -list_add_tail (&ioend->io_list, &failed_ioend_list); -spin_unlock_irqrestore (&failed_ioend_lock, flags); -} -static void ioend_writeback_end_bio (struct bio *bio) {struct iomap_ioend *ioend =iomap_ioend_from_bio (bio); - ioend->io_error =blk_status_to_errno (bio->bi_status); -if (ioend->io_error) { -iomap_fail_ioend_buffered (ioend); +if (bio->bi_status &&bio_complete_in_task (bio))return ; - } - + ioend->io_error =blk_status_to_errno (bio->bi_status);iomap_finish_ioend_buffered_write (ioend); }
Signature · 1 line
2.53.0
Re: [PATCH 2/3] iomap: use bio_complete_in_task for buffered write failures
Quoted 4 lines · Christoph Hellwig
Use
bio_complete_in_taskto defer the bio completion handler to task context instead of the homegrown deferral.Signed-off-by Christoph Hellwig <[email protected]>
Looks about the same as the previous conversion, so
--D
Quoted 71 lines
--- fs/iomap/ioend.c | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-)fs/iomap/ioend.c +2
-46@@ -74,57 +74,13 @@ static u32 iomap_finish_ioend_buffered_write(struct iomap_ioend *ioend)return folio_count; } -static DEFINE_SPINLOCK (failed_ioend_lock); -static LIST_HEAD (failed_ioend_list); - -static void -iomap_fail_ioends ( -struct work_struct *work) -{ -struct iomap_ioend *ioend; -struct list_head tmp; -unsigned long flags; - -spin_lock_irqsave (&failed_ioend_lock, flags); -list_replace_init (&failed_ioend_list, &tmp); -spin_unlock_irqrestore (&failed_ioend_lock, flags); - - while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend, - io_list))) { -list_del_init (&ioend->io_list); -iomap_finish_ioend_buffered_write (ioend); -cond_resched (); - } -} - -static DECLARE_WORK(failed_ioend_work, iomap_fail_ioends); - -static void iomap_fail_ioend_buffered (struct iomap_ioend *ioend) -{ -unsigned long flags; - -/* -* Bounce I/O errors to a workqueue to avoid nested i_lock acquisitions -* in the fserror code. The caller no longer owns the ioend reference -* after the spinlock drops. -*/ -spin_lock_irqsave (&failed_ioend_lock, flags); -if (list_empty (&failed_ioend_list)) -WARN_ON_ONCE (!schedule_work (&failed_ioend_work)); -list_add_tail (&ioend->io_list, &failed_ioend_list); -spin_unlock_irqrestore (&failed_ioend_lock, flags); -} -static void ioend_writeback_end_bio (struct bio *bio) {struct iomap_ioend *ioend =iomap_ioend_from_bio (bio); - ioend->io_error =blk_status_to_errno (bio->bi_status); -if (ioend->io_error) { -iomap_fail_ioend_buffered (ioend); +if (bio->bi_status &&bio_complete_in_task (bio))return ; - } - + ioend->io_error =blk_status_to_errno (bio->bi_status);iomap_finish_ioend_buffered_write (ioend); }Signature · 1 line
2.53.0
Re: [PATCH 2/3] iomap: use bio_complete_in_task for buffered write failures
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Use
bio_complete_in_taskto defer the bio completion handler to task context instead of the homegrown deferral.Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me
Signature · 1 line
- Andrey
PATCH 3/3 iomap: use bio_complete_in_task for buffered simple dio read failures
In reply to Christoph HellwigUse bio_complete_in_task to defer the bio completion handler to task context instead of the homegrown deferral.
--- fs/iomap/direct-io.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
fs/iomap/direct-io.c +1 -18
@@ -919,7 +919,6 @@ struct iomap_dio_simple {struct kiocb *iocb;size_t size;unsigned int dio_flags; -struct work_struct work;/* * Align @bio to a cacheline boundary so that, combined with the * front_pad passed to bioset_init(), the bio sits at the start of
@@ -961,30 +960,14 @@ static ssize_t iomap_dio_simple_complete(struct iomap_dio_simple *sr)return ret; } -static void iomap_dio_simple_complete_work (struct work_struct *work) -{ -struct iomap_dio_simple *sr = - container_of(work, struct iomap_dio_simple, work); -struct kiocb *iocb = sr->iocb; - -WRITE_ONCE (iocb->private,NULL ); - iocb->ki_complete (iocb,iomap_dio_simple_complete (sr)); -} -static void iomap_dio_simple_end_io (struct bio *bio) {struct iomap_dio_simple *sr = container_of(bio, struct iomap_dio_simple, bio);struct kiocb *iocb = sr->iocb; -if (unlikely (sr->bio.bi_status)) { -struct inode *inode =file_inode (iocb->ki_filp); - -INIT_WORK (&sr->work, iomap_dio_simple_complete_work); -queue_work (inode->i_sb->s_dio_done_wq, &sr->work); +if (unlikely (bio->bi_status) &&bio_complete_in_task (bio))return ; - } -WRITE_ONCE (iocb->private,NULL ); iocb->ki_complete (iocb,iomap_dio_simple_complete (sr)); }
Signature · 1 line
2.53.0
Re: [PATCH 3/3] iomap: use bio_complete_in_task for buffered simple dio read failures
Quoted 4 lines · Christoph Hellwig
Use
bio_complete_in_taskto defer the bio completion handler to task context instead of the homegrown deferral.Signed-off-by Christoph Hellwig <[email protected]>
Nice conversion here too.
--D
Quoted 51 lines
--- fs/iomap/direct-io.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)fs/iomap/direct-io.c +1
-18@@ -919,7 +919,6 @@ struct iomap_dio_simple {struct kiocb *iocb;size_t size;unsigned int dio_flags; -struct work_struct work;/* * Align @bio to a cacheline boundary so that, combined with the * front_pad passed to bioset_init(), the bio sits at the start of @@ -961,30 +960,14 @@ static ssize_t iomap_dio_simple_complete(struct iomap_dio_simple *sr)return ret; } -static void iomap_dio_simple_complete_work (struct work_struct *work) -{ -struct iomap_dio_simple *sr = - container_of(work, struct iomap_dio_simple, work); -struct kiocb *iocb = sr->iocb; - -WRITE_ONCE (iocb->private,NULL ); - iocb->ki_complete (iocb,iomap_dio_simple_complete (sr)); -} -static void iomap_dio_simple_end_io (struct bio *bio) {struct iomap_dio_simple *sr = container_of(bio, struct iomap_dio_simple, bio);struct kiocb *iocb = sr->iocb; -if (unlikely (sr->bio.bi_status)) { -struct inode *inode =file_inode (iocb->ki_filp); - -INIT_WORK (&sr->work, iomap_dio_simple_complete_work); -queue_work (inode->i_sb->s_dio_done_wq, &sr->work); +if (unlikely (bio->bi_status) &&bio_complete_in_task (bio))return ; - } -WRITE_ONCE (iocb->private,NULL ); iocb->ki_complete (iocb,iomap_dio_simple_complete (sr)); }Signature · 1 line
2.53.0
Re: [PATCH 3/3] iomap: use bio_complete_in_task for buffered simple dio read failures
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Use
bio_complete_in_taskto defer the bio completion handler to task context instead of the homegrown deferral.Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me
Signature · 1 line
- Andrey
Quoted 11 lines · Christoph Hellwig
this series replaces three pieces of code to queue up I/O completions in user context for error reporting with the relatively new block layer
bio_complete_in_task()mechanism.Diffstat:
bio.c | 46 ++-------------------------------------------- direct-io.c | 19 +------------------ ioend.c | 48 ++---------------------------------------------- 3 files changed, 5 insertions(+), 108 deletions(-)[...]
Applied to the vfs-7.3.iomap.final branch of the vfs/vfs.git tree. Patches in the vfs-7.3.iomap.final branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.3.iomap.final
[1/3] iomap: use bio_complete_in_task for buffered read failures
https://git.kernel.org/vfs/vfs/c/062de5a4ef9d [2/3] iomap: use bio_complete_in_task for buffered write failures https://git.kernel.org/vfs/vfs/c/9d098dfc5522 [3/3] iomap: use bio_complete_in_task for buffered simple dio read failures https://git.kernel.org/vfs/vfs/c/26db1836053f