Skip to content

Commit 6e78262

Browse files
osandovgregkh
authored andcommitted
xfs: fix internal error from AGFL exhaustion
[ Upstream commit f63a5b3769ad7659da4c0420751d78958ab97675 ] We've been seeing XFS errors like the following: XFS: Internal error i != 1 at line 3526 of file fs/xfs/libxfs/xfs_btree.c. Caller xfs_btree_insert+0x1ec/0x280 ... Call Trace: xfs_corruption_error+0x94/0xa0 xfs_btree_insert+0x221/0x280 xfs_alloc_fixup_trees+0x104/0x3e0 xfs_alloc_ag_vextent_size+0x667/0x820 xfs_alloc_fix_freelist+0x5d9/0x750 xfs_free_extent_fix_freelist+0x65/0xa0 __xfs_free_extent+0x57/0x180 ... This is the XFS_IS_CORRUPT() check in xfs_btree_insert() when xfs_btree_insrec() fails. After converting this into a panic and dissecting the core dump, I found that xfs_btree_insrec() is failing because it's trying to split a leaf node in the cntbt when the AG free list is empty. In particular, it's failing to get a block from the AGFL _while trying to refill the AGFL_. If a single operation splits every level of the bnobt and the cntbt (and the rmapbt if it is enabled) at once, the free list will be empty. Then, when the next operation tries to refill the free list, it allocates space. If the allocation does not use a full extent, it will need to insert records for the remaining space in the bnobt and cntbt. And if those new records go in full leaves, the leaves (and potentially more nodes up to the old root) need to be split. Fix it by accounting for the additional splits that may be required to refill the free list in the calculation for the minimum free list size. P.S. As far as I can tell, this bug has existed for a long time -- maybe back to xfs-history commit afdf80ae7405 ("Add XFS_AG_MAXLEVELS macros ...") in April 1994! It requires a very unlucky sequence of events, and in fact we didn't hit it until a particular sparse mmap workload updated from 5.12 to 5.19. But this bug existed in 5.12, so it must've been exposed by some other change in allocation or writeback patterns. It's also much less likely to be hit with the rmapbt enabled, since that increases the minimum free list size and is unlikely to split at the same time as the bnobt and cntbt. Reviewed-by: "Darrick J. Wong" <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Omar Sandoval <[email protected]> Signed-off-by: Chandan Babu R <[email protected]> Signed-off-by: Leah Rumancik <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 323a707 commit 6e78262

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,16 +2273,37 @@ xfs_alloc_min_freelist(
22732273

22742274
ASSERT(mp->m_alloc_maxlevels > 0);
22752275

2276+
/*
2277+
* For a btree shorter than the maximum height, the worst case is that
2278+
* every level gets split and a new level is added, then while inserting
2279+
* another entry to refill the AGFL, every level under the old root gets
2280+
* split again. This is:
2281+
*
2282+
* (full height split reservation) + (AGFL refill split height)
2283+
* = (current height + 1) + (current height - 1)
2284+
* = (new height) + (new height - 2)
2285+
* = 2 * new height - 2
2286+
*
2287+
* For a btree of maximum height, the worst case is that every level
2288+
* under the root gets split, then while inserting another entry to
2289+
* refill the AGFL, every level under the root gets split again. This is
2290+
* also:
2291+
*
2292+
* 2 * (current height - 1)
2293+
* = 2 * (new height - 1)
2294+
* = 2 * new height - 2
2295+
*/
2296+
22762297
/* space needed by-bno freespace btree */
22772298
min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1,
2278-
mp->m_alloc_maxlevels);
2299+
mp->m_alloc_maxlevels) * 2 - 2;
22792300
/* space needed by-size freespace btree */
22802301
min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1,
2281-
mp->m_alloc_maxlevels);
2302+
mp->m_alloc_maxlevels) * 2 - 2;
22822303
/* space needed reverse mapping used space btree */
22832304
if (xfs_has_rmapbt(mp))
22842305
min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1,
2285-
mp->m_rmap_maxlevels);
2306+
mp->m_rmap_maxlevels) * 2 - 2;
22862307

22872308
return min_free;
22882309
}

0 commit comments

Comments
 (0)