]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: rmap btree transaction reservations
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 10 Aug 2016 04:33:22 +0000 (14:33 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 10 Aug 2016 04:33:22 +0000 (14:33 +1000)
Source kernel commit: fa30f03cda26783b1294af6e7da9f1142da0f52e

The rmap btrees will use the AGFL as the block allocation source, so
we need to ensure that the transaction reservations reflect the fact
this tree is modified by allocation and freeing. Hence we need to
extend all the extent allocation/free reservations used in
transactions to handle this.

Note that this also gets rid of the unused XFS_ALLOCFREE_LOG_RES
macro, as we now do buffer reservations based on the number of
buffers logged via xfs_calc_buf_res(). Hence we only need the buffer
count calculation now.

[darrick: use rmap_maxlevels when calculating log block resv]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/xfs_trans_resv.c
libxfs/xfs_trans_resv.h

index c55220f4a80dfabe9f66ff7a3ebd2c7a559090e6..2ed80a56eb8a8ddc30a589805f3eb381b98163d2 100644 (file)
@@ -62,6 +62,30 @@ xfs_calc_buf_res(
        return nbufs * (size + xfs_buf_log_overhead());
 }
 
+/*
+ * Per-extent log reservation for the btree changes involved in freeing or
+ * allocating an extent.  In classic XFS there were two trees that will be
+ * modified (bnobt + cntbt).  With rmap enabled, there are three trees
+ * (rmapbt).  The number of blocks reserved is based on the formula:
+ *
+ * num trees * ((2 blocks/level * max depth) - 1)
+ *
+ * Keep in mind that max depth is calculated separately for each type of tree.
+ */
+static uint
+xfs_allocfree_log_count(
+       struct xfs_mount *mp,
+       uint            num_ops)
+{
+       uint            blocks;
+
+       blocks = num_ops * 2 * (2 * mp->m_ag_maxlevels - 1);
+       if (xfs_sb_version_hasrmapbt(&mp->m_sb))
+               blocks += num_ops * (2 * mp->m_rmap_maxlevels - 1);
+
+       return blocks;
+}
+
 /*
  * Logging inodes is really tricksy. They are logged in memory format,
  * which means that what we write into the log doesn't directly translate into
@@ -125,7 +149,7 @@ xfs_calc_inode_res(
  */
 STATIC uint
 xfs_calc_finobt_res(
-       struct xfs_mount        *mp,
+       struct xfs_mount        *mp,
        int                     alloc,
        int                     modify)
 {
@@ -136,7 +160,7 @@ xfs_calc_finobt_res(
 
        res = xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1));
        if (alloc)
-               res += xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               res += xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                        XFS_FSB_TO_B(mp, 1));
        if (modify)
                res += (uint)XFS_FSB_TO_B(mp, 1);
@@ -187,10 +211,10 @@ xfs_calc_write_reservation(
                     xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
                                      XFS_FSB_TO_B(mp, 1)) +
                     xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
                                      XFS_FSB_TO_B(mp, 1))),
                    (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
                                      XFS_FSB_TO_B(mp, 1))));
 }
 
@@ -216,10 +240,10 @@ xfs_calc_itruncate_reservation(
                     xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
                                      XFS_FSB_TO_B(mp, 1))),
                    (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4),
                                      XFS_FSB_TO_B(mp, 1)) +
                    xfs_calc_buf_res(5, 0) +
-                   xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+                   xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                     XFS_FSB_TO_B(mp, 1)) +
                    xfs_calc_buf_res(2 + mp->m_ialloc_blks +
                                     mp->m_in_maxlevels, 0)));
@@ -246,7 +270,7 @@ xfs_calc_rename_reservation(
                     xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
                                      XFS_FSB_TO_B(mp, 1))),
                    (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 3),
                                      XFS_FSB_TO_B(mp, 1))));
 }
 
@@ -285,7 +309,7 @@ xfs_calc_link_reservation(
                     xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
                                      XFS_FSB_TO_B(mp, 1))),
                    (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                      XFS_FSB_TO_B(mp, 1))));
 }
 
@@ -323,7 +347,7 @@ xfs_calc_remove_reservation(
                     xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
                                      XFS_FSB_TO_B(mp, 1))),
                    (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
                                      XFS_FSB_TO_B(mp, 1))));
 }
 
@@ -370,7 +394,7 @@ xfs_calc_create_resv_alloc(
                mp->m_sb.sb_sectsize +
                xfs_calc_buf_res(mp->m_ialloc_blks, XFS_FSB_TO_B(mp, 1)) +
                xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
-               xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                 XFS_FSB_TO_B(mp, 1));
 }
 
@@ -398,7 +422,7 @@ xfs_calc_icreate_resv_alloc(
        return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
                mp->m_sb.sb_sectsize +
                xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
-               xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                 XFS_FSB_TO_B(mp, 1)) +
                xfs_calc_finobt_res(mp, 0, 0);
 }
@@ -482,7 +506,7 @@ xfs_calc_ifree_reservation(
                xfs_calc_buf_res(1, 0) +
                xfs_calc_buf_res(2 + mp->m_ialloc_blks +
                                 mp->m_in_maxlevels, 0) +
-               xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                 XFS_FSB_TO_B(mp, 1)) +
                xfs_calc_finobt_res(mp, 0, 1);
 }
@@ -512,7 +536,7 @@ xfs_calc_growdata_reservation(
        struct xfs_mount        *mp)
 {
        return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
-               xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                 XFS_FSB_TO_B(mp, 1));
 }
 
@@ -534,7 +558,7 @@ xfs_calc_growrtalloc_reservation(
                xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
                                 XFS_FSB_TO_B(mp, 1)) +
                xfs_calc_inode_res(mp, 1) +
-               xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                 XFS_FSB_TO_B(mp, 1));
 }
 
@@ -610,7 +634,7 @@ xfs_calc_addafork_reservation(
                xfs_calc_buf_res(1, mp->m_dir_geo->blksize) +
                xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
                                 XFS_FSB_TO_B(mp, 1)) +
-               xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
+               xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1),
                                 XFS_FSB_TO_B(mp, 1));
 }
 
@@ -633,7 +657,7 @@ xfs_calc_attrinval_reservation(
                    xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
                                     XFS_FSB_TO_B(mp, 1))),
                   (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
-                   xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
+                   xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4),
                                     XFS_FSB_TO_B(mp, 1))));
 }
 
@@ -700,7 +724,7 @@ xfs_calc_attrrm_reservation(
                                        XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
                     xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
                    (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
-                    xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
+                    xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2),
                                      XFS_FSB_TO_B(mp, 1))));
 }
 
index 797815012c0e31fe711132b3c65aecd5591f7e38..0eb46ed6d404da7d3076e8338f56289ae7f83151 100644 (file)
@@ -67,16 +67,6 @@ struct xfs_trans_resv {
 /* shorthand way of accessing reservation structure */
 #define M_RES(mp)      (&(mp)->m_resv)
 
-/*
- * Per-extent log reservation for the allocation btree changes
- * involved in freeing or allocating an extent.
- * 2 trees * (2 blocks/level * max depth - 1) * block size
- */
-#define        XFS_ALLOCFREE_LOG_RES(mp,nx) \
-       ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * (mp)->m_ag_maxlevels - 1)))
-#define        XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
-       ((nx) * (2 * (2 * (mp)->m_ag_maxlevels - 1)))
-
 /*
  * Per-directory log reservation for any directory change.
  * dir blocks: (1 btree block per level + data block + free block) * dblock size