Thread (6 messages) 6 messages, 3 authors, 2021-02-22

Re: [PATCH] xfs: don't call into blockgc scan with freeze protection

From: "Darrick J. Wong" <djwong@kernel.org>
Date: 2021-02-19 03:24:00

On Thu, Feb 18, 2021 at 03:14:58PM -0500, Brian Foster wrote:
fstest xfs/167 produced a lockdep splat that complained about a
nested transaction acquiring freeze protection during an eofblocks
scan. Drop freeze protection around the block reclaim scan in the
transaction allocation code to avoid this problem.

Signed-off-by: Brian Foster <redacted>
I think it seems reasonable, though I really wish that other patchset to
clean up all the "modify thread state when we start/end transactions"
had landed.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D
quoted hunk ↗ jump to hunk
---
 fs/xfs/xfs_trans.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 44f72c09c203..c32c62d3b77a 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -261,6 +261,7 @@ xfs_trans_alloc(
 {
 	struct xfs_trans	*tp;
 	int			error;
+	bool			retried = false;
 
 	/*
 	 * Allocate the handle before we do our freeze accounting and setting up
@@ -288,19 +289,27 @@ xfs_trans_alloc(
 	INIT_LIST_HEAD(&tp->t_dfops);
 	tp->t_firstblock = NULLFSBLOCK;
 
+retry:
 	error = xfs_trans_reserve(tp, resp, blocks, rtextents);
-	if (error == -ENOSPC) {
+	if (error == -ENOSPC && !retried) {
 		/*
 		 * We weren't able to reserve enough space for the transaction.
 		 * Flush the other speculative space allocations to free space.
 		 * Do not perform a synchronous scan because callers can hold
 		 * other locks.
 		 */
+		retried = true;
+		if (!(flags & XFS_TRANS_NO_WRITECOUNT))
+			sb_end_intwrite(mp->m_super);
 		error = xfs_blockgc_free_space(mp, NULL);
-		if (!error)
-			error = xfs_trans_reserve(tp, resp, blocks, rtextents);
-	}
-	if (error) {
+		if (error) {
+			kmem_cache_free(xfs_trans_zone, tp);
+			return error;
+		}
+		if (!(flags & XFS_TRANS_NO_WRITECOUNT))
+			sb_start_intwrite(mp->m_super);
+		goto retry;
+	} else if (error) {
 		xfs_trans_cancel(tp);
 		return error;
 	}
-- 
2.26.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help