diff mbox series

libxfs: add realtime extent reservation and usage tracking to transactions

Message ID 20201112174345.GT9695@magnolia (mailing list archive)
State Superseded, archived
Headers show
Series libxfs: add realtime extent reservation and usage tracking to transactions | expand

Commit Message

Darrick J. Wong Nov. 12, 2020, 5:43 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

An upcoming patch will add to the deferred ops code the ability to
capture the unfinished deferred ops and transaction reservation for
later replay during log recovery.  This requires transactions to have
the ability to track rt extent reservations and usage, so add that
missing piece now.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
FWIW this should have been a prep patch ahead of "xfs: xfs_defer_capture
should absorb remaining block reservations" but I goofed.  Sorry about
that... :(
---
 include/xfs_trans.h |    2 ++
 libxfs/trans.c      |   14 ++++++++++++++
 2 files changed, 16 insertions(+)

Comments

Christoph Hellwig Nov. 14, 2020, 10:48 a.m. UTC | #1
On Thu, Nov 12, 2020 at 09:43:45AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> An upcoming patch will add to the deferred ops code the ability to
> capture the unfinished deferred ops and transaction reservation for
> later replay during log recovery.  This requires transactions to have
> the ability to track rt extent reservations and usage, so add that
> missing piece now.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> FWIW this should have been a prep patch ahead of "xfs: xfs_defer_capture
> should absorb remaining block reservations" but I goofed.  Sorry about
> that... :(

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/include/xfs_trans.h b/include/xfs_trans.h
index 9292a4a54237..f19914068030 100644
--- a/include/xfs_trans.h
+++ b/include/xfs_trans.h
@@ -64,9 +64,11 @@  typedef struct xfs_trans {
 	unsigned int	t_log_res;		/* amt of log space resvd */
 	unsigned int	t_log_count;		/* count for perm log res */
 	unsigned int	t_blk_res;		/* # of blocks resvd */
+	unsigned int	t_rtx_res;
 	xfs_fsblock_t	t_firstblock;		/* first block allocated */
 	struct xfs_mount *t_mountp;		/* ptr to fs mount struct */
 	unsigned int	t_blk_res_used;		/* # of resvd blocks used */
+	unsigned int	t_rtx_res_used;
 	unsigned int	t_flags;		/* misc flags */
 	long		t_icount_delta;		/* superblock icount change */
 	long		t_ifree_delta;		/* superblock ifree change */
diff --git a/libxfs/trans.c b/libxfs/trans.c
index 6838b727350b..912e95b8d708 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -230,6 +230,7 @@  xfs_trans_reserve(
 			error = -ENOSPC;
 			goto undo_blocks;
 		}
+		tp->t_rtx_res += rtextents;
 	}
 
 	return 0;
@@ -765,6 +766,19 @@  _("Transaction block reservation exceeded! %u > %u\n"),
 		tp->t_ifree_delta += delta;
 		break;
 	case XFS_TRANS_SB_FREXTENTS:
+		/*
+		 * Track the number of rt extents allocated in the transaction.
+		 * Make sure it does not exceed the number reserved.
+		 */
+		if (delta < 0) {
+			tp->t_rtx_res_used += (uint)-delta;
+			if (tp->t_rtx_res_used > tp->t_rtx_res) {
+				fprintf(stderr,
+_("Transaction rt block reservation exceeded! %u > %u\n"),
+					tp->t_rtx_res_used, tp->t_rtx_res);
+				ASSERT(0);
+			}
+		}
 		tp->t_frextents_delta += delta;
 		break;
 	default: