From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Chandan Babu R <chandan.babu@oracle.com>,
"Darrick J. Wong" <djwong@kernel.org>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/9] xfs: split xfs_mod_freecounter
Date: Wed, 21 Feb 2024 11:00:52 +1100 [thread overview]
Message-ID: <ZdU9NAeprkO54iO/@dread.disaster.area> (raw)
In-Reply-To: <20240220160858.GA18908@lst.de>
On Tue, Feb 20, 2024 at 05:08:58PM +0100, Christoph Hellwig wrote:
> On Tue, Feb 20, 2024 at 08:28:21AM +0100, Christoph Hellwig wrote:
> > So we should be fine here, but the code could really use documentation,
> > a few more asserts and a slightly different structure that makes this
> > more obvious. I'll throw in a patch for that.
>
> This is what I ended up with:
>
> ---
> From 22cba925f1f94b22cfa6143a814f1d14a3521621 Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@lst.de>
> Date: Tue, 20 Feb 2024 08:35:27 +0100
> Subject: xfs: block deltas in xfs_trans_unreserve_and_mod_sb must be positive
>
> And to make that more clear, rearrange the code a bit and add asserts
> and a comment.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/xfs_trans.c | 38 ++++++++++++++++++++++++--------------
> 1 file changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
> index 12d45e93f07d50..befb508638ca1f 100644
> --- a/fs/xfs/xfs_trans.c
> +++ b/fs/xfs/xfs_trans.c
> @@ -594,28 +594,38 @@ xfs_trans_unreserve_and_mod_sb(
> {
> struct xfs_mount *mp = tp->t_mountp;
> bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
> - int64_t blkdelta = 0;
> - int64_t rtxdelta = 0;
> + int64_t blkdelta = tp->t_blk_res;
> + int64_t rtxdelta = tp->t_rtx_res;
> int64_t idelta = 0;
> int64_t ifreedelta = 0;
> int error;
>
> - /* calculate deltas */
> - if (tp->t_blk_res > 0)
> - blkdelta = tp->t_blk_res;
> - if ((tp->t_fdblocks_delta != 0) &&
> - (xfs_has_lazysbcount(mp) ||
> - (tp->t_flags & XFS_TRANS_SB_DIRTY)))
> + /*
> + * Calculate the deltas.
> + *
> + * t_fdblocks_delta and t_frextents_delta can be positive or negative:
> + *
> + * - positive values indicate blocks freed in the transaction.
> + * - negative values indicate blocks allocated in the transaction
> + *
> + * Negative values can only happen if the transaction has a block
> + * reservation that covers the allocated block. The end result is
> + * that the calculated delta values must always be positive and we
> + * can only put back previous allocated or reserved blocks here.
> + */
> + ASSERT(tp->t_blk_res || tp->t_fdblocks_delta >= 0);
> + if (xfs_has_lazysbcount(mp) || (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
> blkdelta += tp->t_fdblocks_delta;
> + ASSERT(blkdelta >= 0);
> + }
>
> - if (tp->t_rtx_res > 0)
> - rtxdelta = tp->t_rtx_res;
> - if ((tp->t_frextents_delta != 0) &&
> - (tp->t_flags & XFS_TRANS_SB_DIRTY))
> + ASSERT(tp->t_rtx_res || tp->t_frextents_delta >= 0);
> + if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
> rtxdelta += tp->t_frextents_delta;
> + ASSERT(rtxdelta >= 0);
> + }
>
> - if (xfs_has_lazysbcount(mp) ||
> - (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
> + if (xfs_has_lazysbcount(mp) || (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
> idelta = tp->t_icount_delta;
> ifreedelta = tp->t_ifree_delta;
> }
That seems reasonable - at least it documents the expectations.
-Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2024-02-21 0:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 6:34 bring back RT delalloc support Christoph Hellwig
2024-02-19 6:34 ` [PATCH 1/9] xfs: make XFS_TRANS_LOWMODE match the other XFS_TRANS_ definitions Christoph Hellwig
2024-02-19 6:34 ` [PATCH 2/9] xfs: move RT inode locking out of __xfs_bunmapi Christoph Hellwig
2024-02-19 23:55 ` Dave Chinner
2024-02-20 5:10 ` Christoph Hellwig
2024-02-19 6:34 ` [PATCH 3/9] xfs: split xfs_mod_freecounter Christoph Hellwig
2024-02-19 23:21 ` Dave Chinner
2024-02-20 7:28 ` Christoph Hellwig
2024-02-20 16:08 ` Christoph Hellwig
2024-02-21 0:00 ` Dave Chinner [this message]
2024-02-19 6:34 ` [PATCH 4/9] xfs: reinstate RT support in xfs_bmapi_reserve_delalloc Christoph Hellwig
2024-02-19 6:34 ` [PATCH 5/9] xfs: cleanup fdblock/frextent accounting in xfs_bmap_del_extent_delay Christoph Hellwig
2024-02-19 6:34 ` [PATCH 6/9] xfs: support RT inodes in xfs_mod_delalloc Christoph Hellwig
2024-02-19 23:30 ` Dave Chinner
2024-02-20 5:14 ` Christoph Hellwig
2024-02-19 6:34 ` [PATCH 7/9] xfs: look at m_frextents in xfs_iomap_prealloc_size for RT allocations Christoph Hellwig
2024-02-19 6:34 ` [PATCH 8/9] xfs: stop the steal (of data blocks for RT indirect blocks) Christoph Hellwig
2024-02-19 23:47 ` Dave Chinner
2024-02-20 5:13 ` Christoph Hellwig
2024-02-19 6:34 ` [PATCH 9/9] xfs: reinstate delalloc for RT inodes (if sb_rextsize == 1) Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZdU9NAeprkO54iO/@dread.disaster.area \
--to=david@fromorbit.com \
--cc=chandan.babu@oracle.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox