Skip to content

Commit 93defd5

Browse files
author
Darrick J. Wong
committed
xfs: document the XFS_ALLOC_AGFL_RESERVE constant
Currently, we use this undocumented macro to encode the minimum number of blocks needed to replenish a completely empty AGFL when an AG is nearly full. This has lead to confusion on the part of the maintainers, so let's document what the value actually means, and move it to xfs_alloc.c since it's not used outside of that module. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 01728b4 commit 93defd5

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ xfs_prealloc_blocks(
8282
}
8383

8484
/*
85+
* The number of blocks per AG that we withhold from xfs_mod_fdblocks to
86+
* guarantee that we can refill the AGFL prior to allocating space in a nearly
87+
* full AG. Although the the space described by the free space btrees, the
88+
* blocks used by the freesp btrees themselves, and the blocks owned by the
89+
* AGFL are counted in the ondisk fdblocks, it's a mistake to let the ondisk
90+
* free space in the AG drop so low that the free space btrees cannot refill an
91+
* empty AGFL up to the minimum level. Rather than grind through empty AGs
92+
* until the fs goes down, we subtract this many AG blocks from the incore
93+
* fdblocks to ensure user allocation does not overcommit the space the
94+
* filesystem needs for the AGFLs. The rmap btree uses a per-AG reservation to
95+
* withhold space from xfs_mod_fdblocks, so we do not account for that here.
96+
*/
97+
#define XFS_ALLOCBT_AGFL_RESERVE 4
98+
99+
/*
100+
* Compute the number of blocks that we set aside to guarantee the ability to
101+
* refill the AGFL and handle a full bmap btree split.
102+
*
85103
* In order to avoid ENOSPC-related deadlock caused by out-of-order locking of
86104
* AGF buffer (PV 947395), we place constraints on the relationship among
87105
* actual allocations for data blocks, freelist blocks, and potential file data
@@ -93,14 +111,14 @@ xfs_prealloc_blocks(
93111
* extents need to be actually allocated. To get around this, we explicitly set
94112
* aside a few blocks which will not be reserved in delayed allocation.
95113
*
96-
* We need to reserve 4 fsbs _per AG_ for the freelist and 4 more to handle a
97-
* potential split of the file's bmap btree.
114+
* For each AG, we need to reserve enough blocks to replenish a totally empty
115+
* AGFL and 4 more to handle a potential split of the file's bmap btree.
98116
*/
99117
unsigned int
100118
xfs_alloc_set_aside(
101119
struct xfs_mount *mp)
102120
{
103-
return mp->m_sb.sb_agcount * (XFS_ALLOC_AGFL_RESERVE + 4);
121+
return mp->m_sb.sb_agcount * (XFS_ALLOCBT_AGFL_RESERVE + 4);
104122
}
105123

106124
/*
@@ -124,12 +142,12 @@ xfs_alloc_ag_max_usable(
124142
unsigned int blocks;
125143

126144
blocks = XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)); /* ag headers */
127-
blocks += XFS_ALLOC_AGFL_RESERVE;
145+
blocks += XFS_ALLOCBT_AGFL_RESERVE;
128146
blocks += 3; /* AGF, AGI btree root blocks */
129147
if (xfs_has_finobt(mp))
130148
blocks++; /* finobt root block */
131149
if (xfs_has_rmapbt(mp))
132-
blocks++; /* rmap root block */
150+
blocks++; /* rmap root block */
133151
if (xfs_has_reflink(mp))
134152
blocks++; /* refcount root block */
135153

fs/xfs/libxfs/xfs_alloc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ typedef struct xfs_alloc_arg {
8888
#define XFS_ALLOC_NOBUSY (1 << 2)/* Busy extents not allowed */
8989

9090
/* freespace limit calculations */
91-
#define XFS_ALLOC_AGFL_RESERVE 4
9291
unsigned int xfs_alloc_set_aside(struct xfs_mount *mp);
9392
unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp);
9493

0 commit comments

Comments
 (0)