Skip to content

Commit 4f9a60c

Browse files
committed
xfs: xfs_defer_capture should absorb remaining block reservations
When xfs_defer_capture extracts the deferred ops and transaction state from a transaction, it should record the remaining block reservations so that when we continue the dfops chain, we can reserve the same number of blocks to use. We capture the reservations for both data and realtime volumes. This adds the requirement that every log intent item recovery function must be careful to reserve enough blocks to handle both itself and all defer ops that it can queue. On the other hand, this enables us to do away with the handwaving block estimation nonsense that was going on in xlog_finish_defer_ops. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com>
1 parent e6fff81 commit 4f9a60c

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

fs/xfs/libxfs/xfs_defer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ xfs_defer_ops_capture(
575575
dfc->dfc_tpflags = tp->t_flags & XFS_TRANS_LOWMODE;
576576
tp->t_flags &= ~XFS_TRANS_LOWMODE;
577577

578+
/* Capture the remaining block reservations along with the dfops. */
579+
dfc->dfc_blkres = tp->t_blk_res - tp->t_blk_res_used;
580+
dfc->dfc_rtxres = tp->t_rtx_res - tp->t_rtx_res_used;
581+
578582
return dfc;
579583
}
580584

fs/xfs/libxfs/xfs_defer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ struct xfs_defer_capture {
7575
/* Deferred ops state saved from the transaction. */
7676
struct list_head dfc_dfops;
7777
unsigned int dfc_tpflags;
78+
79+
/* Block reservations for the data and rt devices. */
80+
unsigned int dfc_blkres;
81+
unsigned int dfc_rtxres;
7882
};
7983

8084
/*

fs/xfs/xfs_log_recover.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,27 +2439,12 @@ xlog_finish_defer_ops(
24392439
{
24402440
struct xfs_defer_capture *dfc, *next;
24412441
struct xfs_trans *tp;
2442-
int64_t freeblks;
2443-
uint64_t resblks;
24442442
int error = 0;
24452443

24462444
list_for_each_entry_safe(dfc, next, capture_list, dfc_list) {
2447-
/*
2448-
* We're finishing the defer_ops that accumulated as a result
2449-
* of recovering unfinished intent items during log recovery.
2450-
* We reserve an itruncate transaction because it is the
2451-
* largest permanent transaction type. Since we're the only
2452-
* user of the fs right now, take 93% (15/16) of the available
2453-
* free blocks. Use weird math to avoid a 64-bit division.
2454-
*/
2455-
freeblks = percpu_counter_sum(&mp->m_fdblocks);
2456-
if (freeblks <= 0)
2457-
return -ENOSPC;
2458-
2459-
resblks = min_t(uint64_t, UINT_MAX, freeblks);
2460-
resblks = (resblks * 15) >> 4;
2461-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, resblks,
2462-
0, XFS_TRANS_RESERVE, &tp);
2445+
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
2446+
dfc->dfc_blkres, dfc->dfc_rtxres,
2447+
XFS_TRANS_RESERVE, &tp);
24632448
if (error)
24642449
return error;
24652450

0 commit comments

Comments
 (0)