Skip to content

Commit 5fee784

Browse files
author
Darrick J. Wong
committed
xfs: use deferred frees to reap old btree blocks
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 <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent a55e073 commit 5fee784

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

fs/xfs/scrub/reap.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "xfs_ag_resv.h"
2727
#include "xfs_quota.h"
2828
#include "xfs_qm.h"
29+
#include "xfs_bmap.h"
2930
#include "scrub/scrub.h"
3031
#include "scrub/common.h"
3132
#include "scrub/trace.h"
@@ -81,6 +82,9 @@ struct xrep_reap_state {
8182
/* Reverse mapping owner and metadata reservation type. */
8283
const struct xfs_owner_info *oinfo;
8384
enum xfs_ag_resv_type resv;
85+
86+
/* Number of deferred reaps attached to the current transaction. */
87+
unsigned int deferred;
8488
};
8589

8690
/* Put a block back on the AGFL. */
@@ -165,6 +169,7 @@ xrep_reap_block(
165169
xfs_agnumber_t agno;
166170
xfs_agblock_t agbno;
167171
bool has_other_rmap;
172+
bool need_roll = true;
168173
int error;
169174

170175
agno = XFS_FSB_TO_AGNO(sc->mp, fsbno);
@@ -207,13 +212,25 @@ xrep_reap_block(
207212
xrep_block_reap_binval(sc, fsbno);
208213
error = xrep_put_freelist(sc, agbno);
209214
} else {
215+
/*
216+
* Use deferred frees to get rid of the old btree blocks to try
217+
* to minimize the window in which we could crash and lose the
218+
* old blocks. However, we still need to roll the transaction
219+
* every 100 or so EFIs so that we don't exceed the log
220+
* reservation.
221+
*/
210222
xrep_block_reap_binval(sc, fsbno);
211-
error = xfs_free_extent(sc->tp, sc->sa.pag, agbno, 1, rs->oinfo,
212-
rs->resv);
223+
error = __xfs_free_extent_later(sc->tp, fsbno, 1, rs->oinfo,
224+
rs->resv, true);
225+
if (error)
226+
return error;
227+
rs->deferred++;
228+
need_roll = rs->deferred > 100;
213229
}
214-
if (error)
230+
if (error || !need_roll)
215231
return error;
216232

233+
rs->deferred = 0;
217234
return xrep_roll_ag_trans(sc);
218235
}
219236

@@ -230,8 +247,13 @@ xrep_reap_extents(
230247
.oinfo = oinfo,
231248
.resv = type,
232249
};
250+
int error;
233251

234252
ASSERT(xfs_has_rmapbt(sc->mp));
235253

236-
return xbitmap_walk_bits(bitmap, xrep_reap_block, &rs);
254+
error = xbitmap_walk_bits(bitmap, xrep_reap_block, &rs);
255+
if (error || rs.deferred == 0)
256+
return error;
257+
258+
return xrep_roll_ag_trans(sc);
237259
}

0 commit comments

Comments
 (0)