diff mbox series

[v4.1,11/11] xfs: flush speculative space allocations when we run out of space

Message ID 20210126045952.GR7698@magnolia (mailing list archive)
State Superseded
Headers show
Series None | expand

Commit Message

Darrick J. Wong Jan. 26, 2021, 4:59 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

If a fs modification (creation, file write, reflink, etc.) is unable to
reserve enough space to handle the modification, try clearing whatever
space the filesystem might have been hanging onto in the hopes of
speeding up the filesystem.  The flushing behavior will become
particularly important when we add deferred inode inactivation because
that will increase the amount of space that isn't actively tied to user

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
v4.1: don't free the transaction, since it's not pinning log resources
 fs/xfs/xfs_trans.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series


diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index e72730f85af1..79ef904c5698 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -20,6 +20,8 @@ 
 #include "xfs_trace.h"
 #include "xfs_error.h"
 #include "xfs_defer.h"
+#include "xfs_inode.h"
+#include "xfs_icache.h"
 kmem_zone_t	*xfs_trans_zone;
@@ -285,6 +287,18 @@  xfs_trans_alloc(
 	tp->t_firstblock = NULLFSBLOCK;
 	error = xfs_trans_reserve(tp, resp, blocks, rtextents);
+	if (error == -ENOSPC) {
+		/*
+		 * 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.
+		 */
+		error = xfs_blockgc_free_space(mp, NULL);
+		if (error)
+			return error;
+		error = xfs_trans_reserve(tp, resp, blocks, rtextents);
+	}
 	if (error) {
 		return error;