xfs: ioend batching log reservation deadlock
Subsystems (3)
v2 cover xfs: ioend batching log reservation deadlock
v2:
- Added iomap patch to remove unused ioend->io_private.
- Moved done label in xfs_end_ioend().
v1: https://lore.kernel.org/linux-xfs/[email protected]/
RFD: https://lore.kernel.org/linux-xfs/YF4AOto30pC%2F0FYW@bfoster/
Brian Foster (5):
xfs: drop submit side trans alloc for append ioends
xfs: open code ioend needs workqueue helper
xfs: drop unused ioend private merge and setfilesize code
xfs: drop unnecessary setfilesize helper
iomap: remove unused private field from ioend
fs/iomap/buffered-io.c | 7 +-- fs/xfs/xfs_aops.c | 129 +++++------------------------------------ include/linux/iomap.h | 5 +- 3 files changed, 17 insertions(+), 124 deletions(-)
Signature · 1 line
2.26.3
PATCH v2 1/5 xfs: drop submit side trans alloc for append ioends
Per-inode ioend completion batching has a log reservation deadlock vector between preallocated append transactions and transactions that are acquired at completion time for other purposes (i.e., unwritten extent conversion or COW fork remaps). For example, if the ioend completion workqueue task executes on a batch of ioends that are sorted such that an append ioend sits at the tail, it's possible for the outstanding append transaction reservation to block allocation of transactions required to process preceding ioends in the list.
Append ioend completion is historically the common path for on-disk inode size updates. While file extending writes may have completed sometime earlier, the on-disk inode size is only updated after successful writeback completion. These transactions are preallocated serially from writeback context to mitigate concurrency and associated log reservation pressure across completions processed by multi-threaded workqueue tasks.
However, now that delalloc blocks unconditionally map to unwritten extents at physical block allocation time, size updates via append ioends are relatively rare. This means that inode size updates most commonly occur as part of the preexisting completion time transaction to convert unwritten extents. As a result, there is no longer a strong need to preallocate size update transactions.
Remove the preallocation of inode size update transactions to avoid the ioend completion processing log reservation deadlock. Instead, continue to send all potential size extending ioends to workqueue context for completion and allocate the transaction from that context. This ensures that no outstanding log reservation is owned by the ioend completion worker task when it begins to process ioends.
--- fs/xfs/xfs_aops.c | 45 +++------------------------------------------ 1 file changed, 3 insertions(+), 42 deletions(-)
fs/xfs/xfs_aops.c +3 -42
@@ -39,33 +39,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)XFS_I (ioend->io_inode)->i_d.di_size; } -STATIC int -xfs_setfilesize_trans_alloc ( -struct iomap_ioend *ioend) -{ -struct xfs_mount *mp =XFS_I (ioend->io_inode)->i_mount; -struct xfs_trans *tp; -int error; - - error =xfs_trans_alloc (mp, &M_RES (mp)->tr_fsyncts,0 ,0 ,0 , &tp); -if (error) -return error; - - ioend->io_private = tp; - -/* -* We may pass freeze protection with a transaction. So tell lockdep -* we released it. -*/ -__sb_writers_release (ioend->io_inode->i_sb,SB_FREEZE_FS ); -/* -* We hand off the transaction to the completion thread now, so -* clear the flag here. -*/ -xfs_trans_clear_context (tp); -return 0 ; -} -/* * Update on-disk file size now that data has been written to disk. */
@@ -182,12 +155,10 @@ xfs_end_ioend( error =xfs_reflink_end_cow (ip, offset, size); else if (ioend->io_type == IOMAP_UNWRITTEN) error =xfs_iomap_write_unwritten (ip, offset, size, false); - else - ASSERT(!xfs_ioend_is_append(ioend) || ioend->io_private); +if (!error &&xfs_ioend_is_append (ioend)) + error =xfs_setfilesize (ip, ioend->io_offset, ioend->io_size); done: -if (ioend->io_private) - error =xfs_setfilesize_ioend (ioend, error);iomap_finish_ioends (ioend, error);memalloc_nofs_restore (nofs_flag); }
@@ -237,7 +208,7 @@ xfs_end_io(static inline bool xfs_ioend_needs_workqueue (struct iomap_ioend *ioend) { -return ioend->io_private || +return xfs_ioend_is_append (ioend) || ioend->io_type ==IOMAP_UNWRITTEN || (ioend->io_flags &IOMAP_F_SHARED ); }
@@ -250,8 +221,6 @@ xfs_end_bio(struct xfs_inode *ip =XFS_I (ioend->io_inode);unsigned long flags; -ASSERT (xfs_ioend_needs_workqueue (ioend)); -spin_lock_irqsave (&ip->i_ioend_lock, flags);if (list_empty (&ip->i_ioend_list)) WARN_ON_ONCE(!queue_work(ip->i_mount->m_unwritten_workqueue,
@@ -501,14 +470,6 @@ xfs_prepare_ioend( ioend->io_offset, ioend->io_size); } -/* Reserve log space if we might write beyond the on-disk inode size. */ -if (!status && - ((ioend->io_flags &IOMAP_F_SHARED ) || - ioend->io_type !=IOMAP_UNWRITTEN ) && -xfs_ioend_is_append (ioend) && - !ioend->io_private) - status =xfs_setfilesize_trans_alloc (ioend); -memalloc_nofs_restore (nofs_flag);if (xfs_ioend_needs_workqueue (ioend))
Signature · 1 line
2.26.3
PATCH v2 2/5 xfs: open code ioend needs workqueue helper
In reply to Brian FosterOpen code xfs_ioend_needs_workqueue() into the only remaining caller.
--- fs/xfs/xfs_aops.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
fs/xfs/xfs_aops.c +3 -8
@@ -206,13 +206,6 @@ xfs_end_io( } } -static inline bool xfs_ioend_needs_workqueue (struct iomap_ioend *ioend) -{ -return xfs_ioend_is_append (ioend) || - ioend->io_type ==IOMAP_UNWRITTEN || - (ioend->io_flags &IOMAP_F_SHARED ); -} - STATIC voidxfs_end_bio (struct bio *bio)
@@ -472,7 +465,9 @@ xfs_prepare_ioend(memalloc_nofs_restore (nofs_flag); -if (xfs_ioend_needs_workqueue (ioend)) +/* send ioends that might require a transaction to the completion wq */ +if (xfs_ioend_is_append (ioend) || ioend->io_type ==IOMAP_UNWRITTEN || + (ioend->io_flags &IOMAP_F_SHARED )) ioend->io_bio->bi_end_io = xfs_end_bio;return status; }
Signature · 1 line
2.26.3
PATCH v2 3/5 xfs: drop unused ioend private merge and setfilesize code
In reply to Brian FosterXFS no longer attaches anthing to ioend->io_private. Remove the unnecessary ->io_private merging code. This removes the only remaining user of xfs_setfilesize_ioend() so remove that function as well.
--- fs/xfs/xfs_aops.c | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-)
fs/xfs/xfs_aops.c +1 -45
@@ -85,31 +85,6 @@ xfs_setfilesize(return __xfs_setfilesize (ip, tp, offset, size); } -STATIC int -xfs_setfilesize_ioend ( -struct iomap_ioend *ioend, -int error) -{ -struct xfs_inode *ip =XFS_I (ioend->io_inode); -struct xfs_trans *tp = ioend->io_private; - -/* -* The transaction may have been allocated in the I/O submission thread, -* thus we need to mark ourselves as being in a transaction manually. -* Similarly for freeze protection. -*/ -xfs_trans_set_context (tp); -__sb_writers_acquired (VFS_I (ip)->i_sb,SB_FREEZE_FS ); - -/* we abort the update if there was an IO error */ -if (error) { -xfs_trans_cancel (tp); -return error; - } - -return __xfs_setfilesize (ip, tp, ioend->io_offset, ioend->io_size); -} -/* * IO write completion. */
@@ -163,25 +138,6 @@ xfs_end_ioend(memalloc_nofs_restore (nofs_flag); } -/* -* If the to be merged ioend has a preallocated transaction for file -* size updates we need to ensure the ioend it is merged into also -* has one. If it already has one we can simply cancel the transaction -* as it is guaranteed to be clean. -*/ -static void -xfs_ioend_merge_private ( -struct iomap_ioend *ioend, -struct iomap_ioend *next) -{ -if (!ioend->io_private) { - ioend->io_private = next->io_private; - next->io_private =NULL ; - }else { -xfs_setfilesize_ioend (next, -ECANCELED ); - } -} -/* Finish all pending io completions. */ void xfs_end_io(
@@ -201,7 +157,7 @@ xfs_end_io( while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend, io_list))) {list_del_init (&ioend->io_list); -iomap_ioend_try_merge (ioend, &tmp, xfs_ioend_merge_private); +iomap_ioend_try_merge (ioend, &tmp,NULL );xfs_end_ioend (ioend); } }
Signature · 1 line
2.26.3
PATCH v2 4/5 xfs: drop unnecessary setfilesize helper
In reply to Brian Fosterxfs_setfilesize() is the only remaining caller of the internal __xfs_setfilesize() helper. Fold them into a single function.
--- fs/xfs/xfs_aops.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)
fs/xfs/xfs_aops.c +9 -20
@@ -42,14 +42,20 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)/* * Update on-disk file size now that data has been written to disk. */ -STATIC int -__xfs_setfilesize ( +int +xfs_setfilesize (struct xfs_inode *ip, -struct xfs_trans *tp,xfs_off_t offset,size_t size) { +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp;xfs_fsize_t isize; +int error; + + error =xfs_trans_alloc (mp, &M_RES (mp)->tr_fsyncts,0 ,0 ,0 , &tp); +if (error) +return error;xfs_ilock (ip,XFS_ILOCK_EXCL ); isize =xfs_new_eof (ip, offset + size);
@@ -68,23 +74,6 @@ __xfs_setfilesize(return xfs_trans_commit (tp); } -int -xfs_setfilesize ( -struct xfs_inode *ip, -xfs_off_t offset, -size_t size) -{ -struct xfs_mount *mp = ip->i_mount; -struct xfs_trans *tp; -int error; - - error =xfs_trans_alloc (mp, &M_RES (mp)->tr_fsyncts,0 ,0 ,0 , &tp); -if (error) -return error; - -return __xfs_setfilesize (ip, tp, offset, size); -} -/* * IO write completion. */
Signature · 1 line
2.26.3
PATCH v2 5/5 iomap: remove unused private field from ioend
In reply to Brian FosterThe only remaining user of ->io_private is the generic ioend merging infrastructure. The only user of that is XFS, which no longer sets ->io_private or passes an associated merge callback. Remove the unused parameter and the ->io_private field.
--- fs/iomap/buffered-io.c | 7 +------ fs/xfs/xfs_aops.c | 2 +- include/linux/iomap.h | 5 +---- 3 files changed, 3 insertions(+), 11 deletions(-)
fs/iomap/buffered-io.c +1 -6
@@ -1134,9 +1134,7 @@ iomap_ioend_can_merge(struct iomap_ioend *ioend, struct iomap_ioend *next) }void -iomap_ioend_try_merge (struct iomap_ioend *ioend,struct list_head *more_ioends, -void (*merge_private)(struct iomap_ioend *ioend, -struct iomap_ioend *next)) +iomap_ioend_try_merge (struct iomap_ioend *ioend,struct list_head *more_ioends) {struct iomap_ioend *next;
@@ -1148,8 +1146,6 @@ iomap_ioend_try_merge(struct iomap_ioend *ioend, struct list_head *more_ioends,break ;list_move_tail (&next->io_list, &ioend->io_list); ioend->io_size += next->io_size; -if (next->io_private && merge_private) -merge_private (ioend, next); } }EXPORT_SYMBOL_GPL (iomap_ioend_try_merge);
@@ -1235,7 +1231,6 @@ iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc, ioend->io_inode = inode; ioend->io_size =0 ; ioend->io_offset = offset; - ioend->io_private =NULL ; ioend->io_bio = bio;return ioend; }
fs/xfs/xfs_aops.c +1 -1
@@ -146,7 +146,7 @@ xfs_end_io( while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend, io_list))) {list_del_init (&ioend->io_list); -iomap_ioend_try_merge (ioend, &tmp,NULL ); +iomap_ioend_try_merge (ioend, &tmp);xfs_end_ioend (ioend); } }
include/linux/iomap.h +1 -4
@@ -198,7 +198,6 @@ struct iomap_ioend {struct inode *io_inode;/* file being written to */ size_t io_size;/* size of the extent */ loff_t io_offset;/* offset in the file */ -void *io_private;/* file system private data */ struct bio *io_bio;/* bio being built */ struct bio io_inline_bio;/* MUST BE LAST! */ };
@@ -234,9 +233,7 @@ struct iomap_writepage_ctx {void iomap_finish_ioends (struct iomap_ioend *ioend,int error);void iomap_ioend_try_merge (struct iomap_ioend *ioend, -struct list_head *more_ioends, -void (*merge_private)(struct iomap_ioend *ioend, -struct iomap_ioend *next)); +struct list_head *more_ioends);void iomap_sort_ioends (struct list_head *ioend_list); int iomap_writepage(struct page *page, struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,
Signature · 1 line
2.26.3
Re: [PATCH v2 5/5] iomap: remove unused private field from ioend
Quoted 8 lines · Brian Foster
The only remaining user of ->io_private is the generic ioend merging infrastructure. The only user of that is XFS, which no longer sets ->io_private or passes an associated merge callback. Remove the unused parameter and the ->io_private field.
Signed-off-by Brian Foster <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>
Looks good to me. If anyone actually wants to start using io_private, the time to holler is _right now_.
--D
Quoted 77 lines
--- fs/iomap/buffered-io.c | 7 +------ fs/xfs/xfs_aops.c | 2 +- include/linux/iomap.h | 5 +---- 3 files changed, 3 insertions(+), 11 deletions(-)fs/iomap/buffered-io.c +1
-6@@ -1134,9 +1134,7 @@ iomap_ioend_can_merge(struct iomap_ioend *ioend, struct iomap_ioend *next) }void -iomap_ioend_try_merge (struct iomap_ioend *ioend,struct list_head *more_ioends, -void (*merge_private)(struct iomap_ioend *ioend, -struct iomap_ioend *next)) +iomap_ioend_try_merge (struct iomap_ioend *ioend,struct list_head *more_ioends) {struct iomap_ioend *next;@@ -1148,8 +1146,6 @@ iomap_ioend_try_merge(struct iomap_ioend *ioend, struct list_head *more_ioends,break ;list_move_tail (&next->io_list, &ioend->io_list); ioend->io_size += next->io_size; -if (next->io_private && merge_private) -merge_private (ioend, next); } }EXPORT_SYMBOL_GPL (iomap_ioend_try_merge);@@ -1235,7 +1231,6 @@ iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc, ioend->io_inode = inode; ioend->io_size =0 ; ioend->io_offset = offset; - ioend->io_private =NULL ; ioend->io_bio = bio;return ioend; }fs/xfs/xfs_aops.c +1
-1@@ -146,7 +146,7 @@ xfs_end_io( while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend, io_list))) {list_del_init (&ioend->io_list); -iomap_ioend_try_merge (ioend, &tmp,NULL ); +iomap_ioend_try_merge (ioend, &tmp);xfs_end_ioend (ioend); } }include/linux/iomap.h +1
-4@@ -198,7 +198,6 @@ struct iomap_ioend {struct inode *io_inode;/* file being written to */ size_t io_size;/* size of the extent */ loff_t io_offset;/* offset in the file */ -void *io_private;/* file system private data */ struct bio *io_bio;/* bio being built */ struct bio io_inline_bio;/* MUST BE LAST! */ };@@ -234,9 +233,7 @@ struct iomap_writepage_ctx {void iomap_finish_ioends (struct iomap_ioend *ioend,int error);void iomap_ioend_try_merge (struct iomap_ioend *ioend, -struct list_head *more_ioends, -void (*merge_private)(struct iomap_ioend *ioend, -struct iomap_ioend *next)); +struct list_head *more_ioends);void iomap_sort_ioends (struct list_head *ioend_list); int iomap_writepage(struct page *page, struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,Signature · 1 line
2.26.3