summaryrefslogtreecommitdiff
path: root/fs/xfs/libxfs/xfs_rmap_btree.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-23 14:10:59 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-10-22 16:40:56 -0700
commitcf94cb4944fb956a8d48ef228cb76b8c37182580 (patch)
treecb7eed8e397fff94fe4edc37f735fd622253f67f /fs/xfs/libxfs/xfs_rmap_btree.c
parent3396bc20567d6592ae2cb684e3abd8b70667d851 (diff)
xfs: check absolute maximum nlevels for each btree type
Add code for all five btree types so that we can compute the absolute maximum possible btree height for each btree type, and then check that none of them exceed XFS_BTREE_CUR_ZONE_MAXLEVELS. The code to do the actual checking is a little excessive, but it sets us up for per-type cursor zones in the next patch. xfs_btree_absolute_maxlevels exists to enable xfs_db functionality. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs/libxfs/xfs_rmap_btree.c')
-rw-r--r--fs/xfs/libxfs/xfs_rmap_btree.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c
index ed2670158d6c..2349941f6b13 100644
--- a/fs/xfs/libxfs/xfs_rmap_btree.c
+++ b/fs/xfs/libxfs/xfs_rmap_btree.c
@@ -544,6 +544,38 @@ xfs_rmapbt_maxrecs(
(2 * sizeof(struct xfs_rmap_key) + sizeof(xfs_rmap_ptr_t));
}
+static inline __init unsigned int
+xfs_rmapbt_absolute_maxlevels(void)
+{
+ unsigned int minrecs[2];
+
+ xfs_btree_absolute_minrecs(minrecs,
+ XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING,
+ sizeof(struct xfs_rmap_rec),
+ sizeof(struct xfs_rmap_key) + sizeof(xfs_rmap_ptr_t));
+
+ /*
+ * Compute the asymptotic maxlevels for an rmapbt on any reflink fs.
+ *
+ * On a reflink filesystem, each AG block can have up to 2^32 (per the
+ * refcount record format) owners, which means that theoretically we
+ * could face up to 2^64 rmap records. However, we're likely to run
+ * out of blocks in the AG long before that happens, which means that
+ * we must compute the max height based on what the btree will look
+ * like if it consumes almost all the blocks in the AG due to maximal
+ * sharing factor.
+ */
+ return xfs_btree_compute_maxlevels_size(XFS_MAX_CRC_AG_BLOCKS,
+ minrecs[1]);
+}
+
+int __init
+xfs_rmapbt_create_cursor_cache(void)
+{
+ return xfs_btree_create_cursor_cache(XFS_BTNUM_RMAP, "xfs_rmapbt_cur",
+ xfs_rmapbt_absolute_maxlevels());
+}
+
/* Compute the maximum height of an rmap btree. */
unsigned int
xfs_rmapbt_compute_maxlevels(