Skip to content

Commit 2675ad3

Browse files
Brian FosterDarrick J. Wong
authored andcommitted
xfs: unconditionally read all AGFs on mounts with perag reservation
perag reservation is enabled at mount time on a per AG basis. The upcoming change to set aside allocbt blocks from block reservation requires a populated allocbt counter as soon as possible after mount to be fully effective against large perag reservations. Therefore as a preparation step, initialize the pagf on all mounts where at least one reservation is active. Note that this already occurs to some degree on most default format filesystems as reservation requirement calculations already depend on the AGF or AGI, depending on the reservation type. Signed-off-by: Brian Foster <[email protected]> Reviewed-by: Chandan Babu R <[email protected]> Reviewed-by: Allison Henderson <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent e147a75 commit 2675ad3

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

fs/xfs/libxfs/xfs_ag_resv.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ xfs_ag_resv_init(
253253
xfs_agnumber_t agno = pag->pag_agno;
254254
xfs_extlen_t ask;
255255
xfs_extlen_t used;
256-
int error = 0;
256+
int error = 0, error2;
257+
bool has_resv = false;
257258

258259
/* Create the metadata reservation. */
259260
if (pag->pag_meta_resv.ar_asked == 0) {
@@ -291,6 +292,8 @@ xfs_ag_resv_init(
291292
if (error)
292293
goto out;
293294
}
295+
if (ask)
296+
has_resv = true;
294297
}
295298

296299
/* Create the RMAPBT metadata reservation */
@@ -304,19 +307,28 @@ xfs_ag_resv_init(
304307
error = __xfs_ag_resv_init(pag, XFS_AG_RESV_RMAPBT, ask, used);
305308
if (error)
306309
goto out;
310+
if (ask)
311+
has_resv = true;
307312
}
308313

309-
#ifdef DEBUG
310-
/* need to read in the AGF for the ASSERT below to work */
311-
error = xfs_alloc_pagf_init(pag->pag_mount, tp, pag->pag_agno, 0);
312-
if (error)
313-
return error;
314-
315-
ASSERT(xfs_perag_resv(pag, XFS_AG_RESV_METADATA)->ar_reserved +
316-
xfs_perag_resv(pag, XFS_AG_RESV_RMAPBT)->ar_reserved <=
317-
pag->pagf_freeblks + pag->pagf_flcount);
318-
#endif
319314
out:
315+
/*
316+
* Initialize the pagf if we have at least one active reservation on the
317+
* AG. This may have occurred already via reservation calculation, but
318+
* fall back to an explicit init to ensure the in-core allocbt usage
319+
* counters are initialized as soon as possible. This is important
320+
* because filesystems with large perag reservations are susceptible to
321+
* free space reservation problems that the allocbt counter is used to
322+
* address.
323+
*/
324+
if (has_resv) {
325+
error2 = xfs_alloc_pagf_init(mp, tp, pag->pag_agno, 0);
326+
if (error2)
327+
return error2;
328+
ASSERT(xfs_perag_resv(pag, XFS_AG_RESV_METADATA)->ar_reserved +
329+
xfs_perag_resv(pag, XFS_AG_RESV_RMAPBT)->ar_reserved <=
330+
pag->pagf_freeblks + pag->pagf_flcount);
331+
}
320332
return error;
321333
}
322334

0 commit comments

Comments
 (0)