summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-10-25 17:14:30 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-10-26 18:32:12 -0700
commit7a0d3f33d4189162016b82bdba10d6e0f0f5bd29 (patch)
treef3d8fb6df1be08f84260c399ab8d05d8b1aae5e8
parent70262137ec5dfabacdfc64dc4e76af50dfabdcde (diff)
xfs: use deferred frees to reap old btree blocksrepair-reap-fixes_2020-10-26
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 <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/scrub/repair.c41
-rw-r--r--fs/xfs/scrub/repair.h1
2 files changed, 34 insertions, 8 deletions
diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
index 83388b7c2d12..eeb28bced909 100644
--- a/fs/xfs/scrub/repair.c
+++ b/fs/xfs/scrub/repair.c
@@ -24,6 +24,7 @@
#include "xfs_extent_busy.h"
#include "xfs_ag_resv.h"
#include "xfs_quota.h"
+#include "xfs_bmap.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/trace.h"
@@ -150,6 +151,16 @@ xrep_roll_ag_trans(
return 0;
}
+/* Roll the scrub transaction, holding the primary metadata locked. */
+int
+xrep_roll_trans(
+ struct xfs_scrub *sc)
+{
+ if (!sc->ip)
+ return xrep_roll_ag_trans(sc);
+ return xfs_trans_roll_inode(&sc->tp, sc->ip);
+}
+
/*
* Does the given AG have enough space to rebuild a btree? Neither AG
* reservation can be critical, and we must have enough space (factoring
@@ -516,13 +527,15 @@ 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;
struct xfs_buf *agf_bp = NULL;
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);
@@ -567,17 +580,25 @@ xrep_reap_block(
xrep_reap_invalidate_block(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_reap_invalidate_block(sc, fsbno);
- error = xfs_free_extent(sc->tp, fsbno, 1, oinfo, resv);
+ __xfs_bmap_add_free(sc->tp, fsbno, 1, oinfo, false);
+ (*deferred)++;
+ need_roll = *deferred > 100;
}
if (agf_bp != sc->sa.agf_bp)
xfs_trans_brelse(sc->tp, agf_bp);
- if (error)
+ if (error || !need_roll)
return error;
- if (sc->ip)
- return xfs_trans_roll_inode(&sc->tp, sc->ip);
- return xrep_roll_ag_trans(sc);
+ *deferred = 0;
+ return xrep_roll_trans(sc);
out_free:
if (agf_bp != sc->sa.agf_bp)
@@ -596,6 +617,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_sb_version_hasrmapbt(&sc->mp->m_sb));
@@ -607,12 +629,15 @@ 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;
}
- return error;
+ if (error || deferred == 0)
+ return error;
+
+ return xrep_roll_trans(sc);
}
/*
diff --git a/fs/xfs/scrub/repair.h b/fs/xfs/scrub/repair.h
index 19574535fa0b..a762fc717be1 100644
--- a/fs/xfs/scrub/repair.h
+++ b/fs/xfs/scrub/repair.h
@@ -20,6 +20,7 @@ static inline int xrep_notsupported(struct xfs_scrub *sc)
int xrep_attempt(struct xfs_inode *ip, struct xfs_scrub *sc);
void xrep_failure(struct xfs_mount *mp);
int xrep_roll_ag_trans(struct xfs_scrub *sc);
+int xrep_roll_trans(struct xfs_scrub *sc);
bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks,
enum xfs_ag_resv_type type);
xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc);