Skip to content

Commit

Permalink
xfs: use deferred frees to reap old btree blocks
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
  • Loading branch information
Darrick J. Wong committed Aug 10, 2023
1 parent a55e073 commit 5fee784
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions fs/xfs/scrub/reap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -81,6 +82,9 @@ struct xrep_reap_state {
/* Reverse mapping owner and metadata reservation type. */
const struct xfs_owner_info *oinfo;
enum xfs_ag_resv_type resv;

/* Number of deferred reaps attached to the current transaction. */
unsigned int deferred;
};

/* Put a block back on the AGFL. */
Expand Down Expand Up @@ -165,6 +169,7 @@ xrep_reap_block(
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);
Expand Down Expand Up @@ -207,13 +212,25 @@ 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, sc->sa.pag, agbno, 1, rs->oinfo,
rs->resv);
error = __xfs_free_extent_later(sc->tp, fsbno, 1, rs->oinfo,
rs->resv, true);
if (error)
return error;
rs->deferred++;
need_roll = rs->deferred > 100;
}
if (error)
if (error || !need_roll)
return error;

rs->deferred = 0;
return xrep_roll_ag_trans(sc);
}

Expand All @@ -230,8 +247,13 @@ xrep_reap_extents(
.oinfo = oinfo,
.resv = type,
};
int error;

ASSERT(xfs_has_rmapbt(sc->mp));

return xbitmap_walk_bits(bitmap, xrep_reap_block, &rs);
error = xbitmap_walk_bits(bitmap, xrep_reap_block, &rs);
if (error || rs.deferred == 0)
return error;

return xrep_roll_ag_trans(sc);
}

0 comments on commit 5fee784

Please sign in to comment.