]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: add metadata reservations for realtime rmap btrees
authorDarrick J. Wong <djwong@kernel.org>
Mon, 24 Feb 2025 18:21:49 +0000 (10:21 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 25 Feb 2025 17:15:58 +0000 (09:15 -0800)
Source kernel commit: 8491a55cfc73ff5c2c637a70ade51d4d08abb90a

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_rtrmap_btree.c
libxfs/xfs_rtrmap_btree.h

index 4c3b4a302bd7785159d7d5698025de9bf1af558d..08d1e75f190854f13af47220483cb8adf8811139 100644 (file)
@@ -538,3 +538,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;
+
+       /* Reserve 1% of the rtgroup or enough for 1 block per record. */
+       return max_t(xfs_filblks_t, blocks / 100,
+                       xfs_rtrmapbt_max_size(mp, blocks));
+}
index 7d1a3a49a2d69bdaa98af3f65f3c2b2d3bdc71b0..eaa2942297e20c12db24e17dc3347bdc08dd8ea5 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__ */