]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add metadata reservations for realtime rmap btrees
authorDarrick J. Wong <djwong@kernel.org>
Tue, 15 Oct 2024 19:44:34 +0000 (12:44 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 1 Nov 2024 20:44:56 +0000 (13:44 -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_metafile.c
libxfs/xfs_rtrmap_btree.c
libxfs/xfs_rtrmap_btree.h

index 435b8f8bf6b8189a61a845988eeeade84421f885..ce0e61f023f85a26d605eccaccc097e9f9334180 100644 (file)
@@ -202,7 +202,11 @@ void
 xfs_metafile_resv_free(
        struct xfs_inode        *ip)
 {
-       if (!ip)
+       /*
+        * We can end up here for the rt bitmap/summary inodes that don't have
+        * reservations.  Just exist early in that case.
+        */
+       if (!ip || !ip->i_delayed_blks)
                return;
 
        ASSERT(xfs_is_metadir_inode(ip));
index 6e780f1bd9663d49eccf78d7adaed5df11254713..93ab59ff027e04f394772e42ac736a4a5d819a04 100644 (file)
@@ -539,3 +539,44 @@ 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)
+{
+       uint32_t                blocks = mp->m_groups[XG_TYPE_RTG].blocks;
+
+       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, blocks >> 6,
+                       xfs_rtrmapbt_max_size(mp, blocks));
+}
index 63aabae2e09db1eb6e733f2e3b3deec614e39e3e..ad5cb1078bc1a002e8d903f23484af9202b62869 100644 (file)
@@ -79,4 +79,6 @@ unsigned int xfs_rtrmapbt_maxlevels_ondisk(void);
 int __init xfs_rtrmapbt_init_cur_cache(void);
 void xfs_rtrmapbt_destroy_cur_cache(void);
 
+xfs_filblks_t xfs_rtrmapbt_calc_reserves(struct xfs_mount *mp);
+
 #endif /* __XFS_RTRMAP_BTREE_H__ */