Skip to contentSkip to conversation

xfs: flush delalloc blocks on ENOSPC in xfs_trans_alloc_icreate

PATCH Applied Ravi Singh 3 participants 4 messages Apr 22 – Apr 27

Subsystems (2)
lore
Share & tools
lore

Ravi Singh

author
#0 lore raw

PATCH v3 1/1 xfs: flush delalloc blocks on ENOSPC in xfs_trans_alloc_icreate

xfs_trans_alloc_icreate() can fail with ENOSPC when delalloc reservations have consumed most of the available block count (fdblocks). xfs_trans_alloc() already retries internally with xfs_blockgc_flush_all(), but that only trims post-EOF speculative preallocation and may not free enough space for the transaction reservation.

Add a retry with xfs_flush_inodes() when xfs_trans_alloc() returns ENOSPC. This forces writeback of all dirty inodes via sync_inodes_sb(), converting delalloc reservations to real allocations and freeing the over-reserved portion back to fdblocks.

This fixes all callers of xfs_trans_alloc_icreate() and removes the existing caller-level retry from xfs_create(), which is now handled centrally.

---

v3:
- Moved comment to sit above the flush+retry code (Christoph)

v2:
- Moved xfs_flush_inodes() retry into xfs_trans_alloc_icreate() instead of xfs_symlink() (Christoph)
- Removed caller-level retry from xfs_create()
- All callers now covered: xfs_create, xfs_symlink, xfs_create_tmpfile, xcrep_tempfile_create

 fs/xfs/xfs_inode.c |  6 ------
 fs/xfs/xfs_trans.c | 11 +++++++++++
 2 files changed, 11 insertions(+), 6 deletions(-)
fs/xfs/xfs_inode.c +0 -6
index beaa26ec62da..9978ac1422fc 100644
@@ -699,12 +699,6 @@ xfs_create(
 	 */
 	error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp, resblks,
 			&tp);
-	if (error == -ENOSPC) {
-		/* flush outstanding delalloc blocks and retry */
-		xfs_flush_inodes(mp);
-		error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp,
-				resblks, &tp);
-	}
 	if (error)
 		goto out_parent;
 
fs/xfs/xfs_trans.c +11 -0
index bcc470f56e46..148cc32449c1 100644
@@ -1199,10 +1199,21 @@ xfs_trans_alloc_icreate(
 {
 	struct xfs_trans	*tp;
 	bool			retried = false;
+	bool			flushed = false;
 	int			error;
 
 retry:
 	error = xfs_trans_alloc(mp, resv, dblocks, 0, 0, &tp);
+	if (error == -ENOSPC && !flushed) {
+		/*
+		 * Flush all delalloc blocks to reclaim space from speculative
+		 * preallocation.  This is similar to the quota retry below
+		 * but targets FS-wide ENOSPC.
+		 */
+		xfs_flush_inodes(mp);
+		flushed = true;
+		goto retry;
+	}
 	if (error)
 		return error;
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v3 1/1
#2 lore raw
In reply to Ravi Singh
Quoted 12 lines · Ravi Singh

xfs_trans_alloc_icreate() can fail with ENOSPC when delalloc reservations have consumed most of the available block count (fdblocks). xfs_trans_alloc() already retries internally with xfs_blockgc_flush_all(), but that only trims post-EOF speculative preallocation and may not free enough space for the transaction reservation.

Add a retry with xfs_flush_inodes() when xfs_trans_alloc() returns ENOSPC. This forces writeback of all dirty inodes via sync_inodes_sb(), converting delalloc reservations to real allocations and freeing the over-reserved portion back to fdblocks.

Quoted 6 lines

This fixes all callers of xfs_trans_alloc_icreate() and removes the existing caller-level retry from xfs_create(), which is now handled centrally.

---

Looks good

Quoted 63 lines

v3:
- Moved comment to sit above the flush+retry code (Christoph)

v2:
- Moved xfs_flush_inodes() retry into xfs_trans_alloc_icreate() instead of xfs_symlink() (Christoph)
- Removed caller-level retry from xfs_create()
- All callers now covered: xfs_create, xfs_symlink, xfs_create_tmpfile, xcrep_tempfile_create

 fs/xfs/xfs_inode.c |  6 ------
 fs/xfs/xfs_trans.c | 11 +++++++++++
 2 files changed, 11 insertions(+), 6 deletions(-)
fs/xfs/xfs_inode.c +0 -6
index beaa26ec62da..9978ac1422fc 100644
@@ -699,12 +699,6 @@ xfs_create(
 	 */
 	error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp, resblks,
 			&tp);
-	if (error == -ENOSPC) {
-		/* flush outstanding delalloc blocks and retry */
-		xfs_flush_inodes(mp);
-		error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp,
-				resblks, &tp);
-	}
 	if (error)
 		goto out_parent;
 
fs/xfs/xfs_trans.c +11 -0
index bcc470f56e46..148cc32449c1 100644
@@ -1199,10 +1199,21 @@ xfs_trans_alloc_icreate(
 {
 	struct xfs_trans	*tp;
 	bool			retried = false;
+	bool			flushed = false;
 	int			error;
 
 retry:
 	error = xfs_trans_alloc(mp, resv, dblocks, 0, 0, &tp);
+	if (error == -ENOSPC && !flushed) {
+		/*
+		 * Flush all delalloc blocks to reclaim space from speculative
+		 * preallocation.  This is similar to the quota retry below
+		 * but targets FS-wide ENOSPC.
+		 */
+		xfs_flush_inodes(mp);
+		flushed = true;
+		goto retry;
+	}
 	if (error)
 		return error;
 
Signature · 1 line
2.53.0
maintainer Applied
#3 lore raw
In reply to Ravi Singh
Quoted 8 lines · Ravi Singh

xfs_trans_alloc_icreate() can fail with ENOSPC when delalloc reservations have consumed most of the available block count (fdblocks). xfs_trans_alloc() already retries internally with xfs_blockgc_flush_all(), but that only trims post-EOF speculative preallocation and may not free enough space for the transaction reservation.

[...]

Applied to for-next, thanks!

[1/1] xfs: flush delalloc blocks on ENOSPC in xfs_trans_alloc_icreate

      commit: 87e63466c9fc30c3d95b8741c3df1f1ff01d7f23

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>