]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add metadata reservations for realtime rmap btrees
authorDarrick J. Wong <djwong@kernel.org>
Sat, 10 Aug 2024 19:41:15 +0000 (21:41 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2024 11:53:50 +0000 (13:53 +0200)
Source kernel commit: 96e6d68712d5d66f3980fc5e6f889c4428bf8c38

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

index 5c70e1cf21d7277edaa2822307f2c42cbd2704b0..fd537db3201a1ec72b5494905d2a9f5f5d68fa9b 100644 (file)
@@ -203,7 +203,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 e421635afcab2e30f7d895d3a790b367ea4d5625..d3f7760eaeffec242fd8af9da0bb5dee8d366511 100644 (file)
@@ -544,3 +544,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_rgblocks >> 6,
+                       xfs_rtrmapbt_max_size(mp, mp->m_rgblocks));
+}
index 0f732679719242cd8766354d26cebc3a54d4c776..bb0ebc07f47e0f6245a77422d1d73455c65a6103 100644 (file)
@@ -80,4 +80,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__ */