]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
xfs: add metadata reservations for realtime refcount btree
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:20:53 +0000 (16:20 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 23 Dec 2024 21:06:11 +0000 (13:06 -0800)
Reserve some free blocks so that we will always have enough free blocks
in the data volume to handle expansion of the realtime refcount btree.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_rtrefcount_btree.c
fs/xfs/libxfs/xfs_rtrefcount_btree.h
fs/xfs/xfs_rtalloc.c

index ebbeab112d141255f05b41118dab0697419cec00..ff72ed09e75f0876f44e0f56e225323d8d31b8ef 100644 (file)
@@ -419,3 +419,41 @@ xfs_rtrefcountbt_compute_maxlevels(
        /* Add one level to handle the inode root level. */
        mp->m_rtrefc_maxlevels = min(d_maxlevels, r_maxlevels) + 1;
 }
+
+/* Calculate the rtrefcount btree size for some records. */
+unsigned long long
+xfs_rtrefcountbt_calc_size(
+       struct xfs_mount        *mp,
+       unsigned long long      len)
+{
+       return xfs_btree_calc_size(mp->m_rtrefc_mnr, len);
+}
+
+/*
+ * Calculate the maximum refcount btree size.
+ */
+static unsigned long long
+xfs_rtrefcountbt_max_size(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtblocks)
+{
+       /* Bail out if we're uninitialized, which can happen in mkfs. */
+       if (mp->m_rtrefc_mxr[0] == 0)
+               return 0;
+
+       return xfs_rtrefcountbt_calc_size(mp, rtblocks);
+}
+
+/*
+ * Figure out how many blocks to reserve and how many are used by this btree.
+ * We need enough space to hold one record for every rt extent in the rtgroup.
+ */
+xfs_filblks_t
+xfs_rtrefcountbt_calc_reserves(
+       struct xfs_mount        *mp)
+{
+       if (!xfs_has_rtreflink(mp))
+               return 0;
+
+       return xfs_rtrefcountbt_max_size(mp, mp->m_sb.sb_rgextents);
+}
index b713b33818800c66a1879e56f8245d975e99defe..3cd44590c9304c599acba0d7cf216d16120ae225 100644 (file)
@@ -67,4 +67,8 @@ unsigned int xfs_rtrefcountbt_maxlevels_ondisk(void);
 int __init xfs_rtrefcountbt_init_cur_cache(void);
 void xfs_rtrefcountbt_destroy_cur_cache(void);
 
+xfs_filblks_t xfs_rtrefcountbt_calc_reserves(struct xfs_mount *mp);
+unsigned long long xfs_rtrefcountbt_calc_size(struct xfs_mount *mp,
+               unsigned long long len);
+
 #endif /* __XFS_RTREFCOUNT_BTREE_H__ */
index a69967f9d88ead37e860e01a63b1ee71423f0f72..294aa0739be311ee0606f22f9c81e655af823930 100644 (file)
@@ -31,6 +31,7 @@
 #include "xfs_rtgroup.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
+#include "xfs_rtrefcount_btree.h"
 
 /*
  * Return whether there are any free extents in the size range given
@@ -1547,6 +1548,11 @@ xfs_rt_resv_init(
                err2 = xfs_metafile_resv_init(rtg_rmap(rtg), ask);
                if (err2 && !error)
                        error = err2;
+
+               ask = xfs_rtrefcountbt_calc_reserves(mp);
+               err2 = xfs_metafile_resv_init(rtg_refcount(rtg), ask);
+               if (err2 && !error)
+                       error = err2;
        }
 
        return error;