summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 10:40:17 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-12-15 17:28:48 -0800
commite956ab19d9060e5a29e4727ffcf4ed710b15447c (patch)
treec43d1a28e6c87327c49814d8fd89d8a662b79c9f
parent952bd58839084e3cb33f9cdd40b1e39472bfdf74 (diff)
xfs: use deferred frees to reap old btree blocksrepair-reap-fixes_2021-12-15
Use deferred frees (EFIs) to reap the blocks of a btree that we just replaced. This helps us to shrink the window in which those old blocks could be lost due to a system crash, though we try to flush the EFIs every few hundred blocks so that we don't also overflow the transaction reservations during and after we commit the new btree. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/scrub/repair.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
index 69e48d13bd94..ffe47e534240 100644
--- a/fs/xfs/scrub/repair.c
+++ b/fs/xfs/scrub/repair.c
@@ -26,6 +26,7 @@
#include "xfs_ag_resv.h"
#include "xfs_quota.h"
#include "xfs_qm.h"
+#include "xfs_bmap.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/trace.h"
@@ -524,12 +525,14 @@ xrep_reap_block(
struct xfs_scrub *sc,
xfs_fsblock_t fsbno,
const struct xfs_owner_info *oinfo,
- enum xfs_ag_resv_type resv)
+ enum xfs_ag_resv_type resv,
+ unsigned int *deferred)
{
struct xfs_btree_cur *cur;
xfs_agnumber_t agno;
xfs_agblock_t agbno;
bool has_other_rmap;
+ bool need_roll = true;
int error;
agno = XFS_FSB_TO_AGNO(sc->mp, fsbno);
@@ -569,12 +572,22 @@ xrep_reap_block(
xrep_block_reap_binval(sc, fsbno);
error = xrep_put_freelist(sc, agbno);
} else {
+ /*
+ * Use deferred frees to get rid of the old btree blocks to try
+ * to minimize the window in which we could crash and lose the
+ * old blocks. However, we still need to roll the transaction
+ * every 100 or so EFIs so that we don't exceed the log
+ * reservation.
+ */
xrep_block_reap_binval(sc, fsbno);
- error = xfs_free_extent(sc->tp, fsbno, 1, oinfo, resv);
+ __xfs_free_extent_later(sc->tp, fsbno, 1, oinfo, true);
+ (*deferred)++;
+ need_roll = *deferred > 100;
}
- if (error)
+ if (error || !need_roll)
return error;
+ *deferred = 0;
return xrep_roll_ag_trans(sc);
}
@@ -589,6 +602,7 @@ xrep_reap_extents(
struct xbitmap_range *bmr;
struct xbitmap_range *n;
xfs_fsblock_t fsbno;
+ unsigned int deferred = 0;
int error = 0;
ASSERT(xfs_has_rmapbt(sc->mp));
@@ -600,12 +614,14 @@ xrep_reap_extents(
XFS_FSB_TO_AGNO(sc->mp, fsbno),
XFS_FSB_TO_AGBNO(sc->mp, fsbno), 1);
- error = xrep_reap_block(sc, fsbno, oinfo, type);
+ error = xrep_reap_block(sc, fsbno, oinfo, type, &deferred);
if (error)
break;
}
+ if (error || deferred == 0)
+ return error;
- return error;
+ return xrep_roll_ag_trans(sc);
}
/*