summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-08-30 15:44:43 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2019-11-22 21:34:59 -0800
commit13b4e125532b29d5950525a0605b5bc580e536fe (patch)
tree018c06b137ff582632f7254a94d2c5c83116a5cb
parent8dda7f80597d6f696f1b369691228c7c164cd70d (diff)
xfs: use deferred frees to reap old btree blocksrepair-reap-fixes_2019-11-22
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.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
index 62a9b77eba3d..477df76174b9 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"
@@ -510,13 +511,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);
@@ -563,14 +566,24 @@ 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;
+ *deferred = 0;
if (sc->ip)
return xfs_trans_roll_inode(&sc->tp, sc->ip);
return xrep_roll_ag_trans(sc);
@@ -592,6 +605,7 @@ xrep_reap_extents(
struct xfs_bitmap_range *bmr;
struct xfs_bitmap_range *n;
xfs_fsblock_t fsbno;
+ unsigned int deferred = 0;
int error = 0;
ASSERT(xfs_sb_version_hasrmapbt(&sc->mp->m_sb));
@@ -603,12 +617,17 @@ 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;
+
+ if (sc->ip)
+ return xfs_trans_roll_inode(&sc->tp, sc->ip);
+ return xrep_roll_ag_trans(sc);
}
/*