]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add metadata reservations for realtime rmap btrees
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:22:17 +0000 (14:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jul 2024 22:37:19 +0000 (15:37 -0700)
Reserve some free blocks so that we will always have enough free blocks
in the data volume to handle expansion of the realtime rmap btree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_rtrmap_btree.c
libxfs/xfs_rtrmap_btree.h

index 8717df3d1798f53b044704abe4e7649f8f9f5e79..534630da0d8896a0dead17fbe8452942519007a7 100644 (file)
@@ -543,3 +543,42 @@ xfs_rtrmapbt_compute_maxlevels(
        /* Add one level to handle the inode root level. */
        mp->m_rtrmap_maxlevels = min(d_maxlevels, r_maxlevels) + 1;
 }
+
+/* Calculate the rtrmap btree size for some records. */
+static unsigned long long
+xfs_rtrmapbt_calc_size(
+       struct xfs_mount        *mp,
+       unsigned long long      len)
+{
+       return xfs_btree_calc_size(mp->m_rtrmap_mnr, len);
+}
+
+/*
+ * Calculate the maximum rmap btree size.
+ */
+static unsigned long long
+xfs_rtrmapbt_max_size(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtblocks)
+{
+       /* Bail out if we're uninitialized, which can happen in mkfs. */
+       if (mp->m_rtrmap_mxr[0] == 0)
+               return 0;
+
+       return xfs_rtrmapbt_calc_size(mp, rtblocks);
+}
+
+/*
+ * Figure out how many blocks to reserve and how many are used by this btree.
+ */
+xfs_filblks_t
+xfs_rtrmapbt_calc_reserves(
+       struct xfs_mount        *mp)
+{
+       if (!xfs_has_rtrmapbt(mp))
+               return 0;
+
+       /* 1/64th (~1.5%) of the space, and enough for 1 record per block. */
+       return max_t(xfs_filblks_t, mp->m_sb.sb_rgblocks >> 6,
+                       xfs_rtrmapbt_max_size(mp, mp->m_sb.sb_rgblocks));
+}
index 6ce76b828de0f363cff8f1adb75816783c42c56b..8887b53aa9247e9f15b9a830c4eae9fcd2197815 100644 (file)
@@ -84,4 +84,6 @@ void xfs_rtrmapbt_destroy_cur_cache(void);
 #define xfs_rtrmapbt_create_path(mp, rgno) \
        xfs_rtinode_create_path((mp), (rgno), "rmap")
 
+xfs_filblks_t xfs_rtrmapbt_calc_reserves(struct xfs_mount *mp);
+
 #endif /* __XFS_RTRMAP_BTREE_H__ */