]> www.infradead.org Git - users/hch/misc.git/commitdiff
xfs: add frextents to the lazysbcounters when rtgroups enabled
authorDarrick J. Wong <djwong@kernel.org>
Wed, 29 May 2024 04:11:17 +0000 (21:11 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 24 Jul 2024 05:33:36 +0000 (22:33 -0700)
Make the free rt extent count a part of the lazy sb counters when the
realtime groups feature is enabled.  This is possible because the patch
to recompute frextents from the rtbitmap during log recovery predates
the code adding rtgroup support, hence we know that the value will
always be correct during runtime.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_sb.c
fs/xfs/scrub/fscounters_repair.c
fs/xfs/xfs_trans.c

index 64cb2f905a78fe45a997ecece7bb567d7ab7add1..d7c2a250d0964f5d0ab0beafdf6088f15e5010e2 100644 (file)
@@ -1143,6 +1143,11 @@ xfs_log_sb(
         * sb counters, despite having a percpu counter. It is always kept
         * consistent with the ondisk rtbitmap by xfs_trans_apply_sb_deltas()
         * and hence we don't need have to update it here.
+        *
+        * sb_frextents was added to the lazy sb counters when the rt groups
+        * feature was introduced.  This counter can go negative due to the way
+        * we handle nearly-lockless reservations, so we must use the _positive
+        * variant here to avoid writing out nonsense frextents.
         */
        if (xfs_has_lazysbcount(mp)) {
                mp->m_sb.sb_icount = percpu_counter_sum_positive(&mp->m_icount);
@@ -1152,6 +1157,9 @@ xfs_log_sb(
                mp->m_sb.sb_fdblocks =
                                percpu_counter_sum_positive(&mp->m_fdblocks);
        }
+       if (xfs_has_rtgroups(mp))
+               mp->m_sb.sb_frextents =
+                               percpu_counter_sum_positive(&mp->m_frextents);
 
        xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
        xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
index 469bf645dbea52643a77afd138aff902f34bb207..cda13447a373e14240acbd3f33d153138e8e141e 100644 (file)
@@ -68,15 +68,16 @@ xrep_fscounters(
 
        /*
         * Online repair is only supported on v5 file systems, which require
-        * lazy sb counters and thus no update of sb_fdblocks here.  But as of
-        * now we don't support lazy counting sb_frextents yet, and thus need
-        * to also update it directly here.  And for that we need to keep
+        * lazy sb counters and thus no update of sb_fdblocks here.  But
+        * sb_frextents only uses a lazy counter with rtgroups, and thus needs
+        * to be updated directly here otherwise.  And for that we need to keep
         * track of the delalloc reservations separately, as they are are
         * subtracted from m_frextents, but not included in sb_frextents.
         */
        percpu_counter_set(&mp->m_frextents,
                fsc->frextents - fsc->frextents_delayed);
-       mp->m_sb.sb_frextents = fsc->frextents;
+       if (!xfs_has_rtgroups(mp))
+               mp->m_sb.sb_frextents = fsc->frextents;
 
        return 0;
 }
index c130cfd8b0028769bba4f5474652778e92f558c1..dc90856e1e9bba0bc66c4ed11c4d9a7b759c3a4a 100644 (file)
@@ -421,6 +421,8 @@ xfs_trans_mod_sb(
                        ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res);
                }
                tp->t_frextents_delta += delta;
+               if (xfs_has_rtgroups(mp))
+                       flags &= ~XFS_TRANS_SB_DIRTY;
                break;
        case XFS_TRANS_SB_RES_FREXTENTS:
                /*
@@ -514,8 +516,14 @@ xfs_trans_apply_sb_deltas(
         *
         * Don't touch m_frextents because it includes incore reservations,
         * and those are handled by the unreserve function.
+        *
+        * sb_frextents was added to the lazy sb counters when the rt groups
+        * feature was introduced.  This is possible because we know that all
+        * kernels supporting rtgroups will also recompute frextents from the
+        * realtime bitmap.
         */
-       if (tp->t_frextents_delta || tp->t_res_frextents_delta) {
+       if ((tp->t_frextents_delta || tp->t_res_frextents_delta) &&
+           !xfs_has_rtgroups(tp->t_mountp)) {
                struct xfs_mount        *mp = tp->t_mountp;
                int64_t                 rtxdelta;
 
@@ -627,7 +635,7 @@ xfs_trans_unreserve_and_mod_sb(
        }
 
        ASSERT(tp->t_rtx_res || tp->t_frextents_delta >= 0);
-       if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
+       if (xfs_has_rtgroups(mp) || (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
                rtxdelta += tp->t_frextents_delta;
                ASSERT(rtxdelta >= 0);
        }
@@ -663,8 +671,11 @@ xfs_trans_unreserve_and_mod_sb(
         * Do not touch sb_frextents here because we are dealing with incore
         * reservation.  sb_frextents is not part of the lazy sb counters so it
         * must be consistent with the ondisk rtbitmap and must never include
-        * incore reservations.
+        * incore reservations.  sb_frextents was added to the lazy sb counters
+        * when the realtime groups feature was introduced.
         */
+       if (xfs_has_rtgroups(mp))
+               mp->m_sb.sb_frextents += rtxdelta;
        mp->m_sb.sb_dblocks += tp->t_dblocks_delta;
        mp->m_sb.sb_agcount += tp->t_agcount_delta;
        mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta;