From: "Darrick J. Wong" <djwong@kernel.org>
To: Chandan Babu R <chandan.babu@oracle.com>
Cc: linux-xfs@vger.kernel.org, david@fromorbit.com
Subject: Re: [PATCH V4 16/16] xfs: Define max extent length based on on-disk format definition
Date: Tue, 4 Jan 2022 16:47:06 -0800 [thread overview]
Message-ID: <20220105004706.GT31583@magnolia> (raw)
In-Reply-To: <20211214084519.759272-17-chandan.babu@oracle.com>
On Tue, Dec 14, 2021 at 02:15:19PM +0530, Chandan Babu R wrote:
> The maximum extent length depends on maximum block count that can be stored in
> a BMBT record. Hence this commit defines MAXEXTLEN based on
> BMBT_BLOCKCOUNT_BITLEN.
>
> While at it, the commit also renames MAXEXTLEN to XFS_MAX_BMBT_EXTLEN.
>
> Suggested-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
> ---
> fs/xfs/libxfs/xfs_alloc.c | 2 +-
> fs/xfs/libxfs/xfs_bmap.c | 57 +++++++++++++++++-----------------
> fs/xfs/libxfs/xfs_format.h | 21 +++++++------
> fs/xfs/libxfs/xfs_inode_buf.c | 4 +--
> fs/xfs/libxfs/xfs_trans_resv.c | 11 ++++---
> fs/xfs/scrub/bmap.c | 2 +-
> fs/xfs/xfs_bmap_util.c | 14 +++++----
> fs/xfs/xfs_iomap.c | 28 ++++++++---------
> 8 files changed, 72 insertions(+), 67 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index 353e53b892e6..3f9b9cbfef43 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -2493,7 +2493,7 @@ __xfs_free_extent_later(
>
> ASSERT(bno != NULLFSBLOCK);
> ASSERT(len > 0);
> - ASSERT(len <= MAXEXTLEN);
> + ASSERT(len <= XFS_MAX_BMBT_EXTLEN);
> ASSERT(!isnullstartblock(bno));
> agno = XFS_FSB_TO_AGNO(mp, bno);
> agbno = XFS_FSB_TO_AGBNO(mp, bno);
Yessss another unprefixed constant goes away.
<snip>
> diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> index 3183f78fe7a3..dd5cffe63be3 100644
> --- a/fs/xfs/libxfs/xfs_format.h
> +++ b/fs/xfs/libxfs/xfs_format.h
> @@ -885,15 +885,6 @@ enum xfs_dinode_fmt {
> { XFS_DINODE_FMT_BTREE, "btree" }, \
> { XFS_DINODE_FMT_UUID, "uuid" }
>
> -/*
> - * Max values for extlen, extnum, aextnum.
> - */
> -#define MAXEXTLEN ((xfs_extlen_t)0x1fffff) /* 21 bits */
> -#define XFS_MAX_EXTCNT_DATA_FORK ((xfs_extnum_t)0xffffffffffff) /* Unsigned 48-bits */
> -#define XFS_MAX_EXTCNT_ATTR_FORK ((xfs_aextnum_t)0xffffffff) /* Unsigned 32-bits */
> -#define XFS_MAX_EXTCNT_DATA_FORK_OLD ((xfs_extnum_t)0x7fffffff) /* Signed 32-bits */
> -#define XFS_MAX_EXTCNT_ATTR_FORK_OLD ((xfs_aextnum_t)0x7fff) /* Signed 16-bits */
> -
> /*
> * Inode minimum and maximum sizes.
> */
> @@ -1623,7 +1614,17 @@ typedef struct xfs_bmdr_block {
> #define BMBT_BLOCKCOUNT_BITLEN 21
>
> #define BMBT_STARTOFF_MASK ((1ULL << BMBT_STARTOFF_BITLEN) - 1)
> -#define BMBT_BLOCKCOUNT_MASK ((1ULL << BMBT_BLOCKCOUNT_BITLEN) - 1)
> +
> +/*
> + * Max values for extlen and disk inode's extent counters.
Nit: 'ondisk inode'
> + */
> +#define XFS_MAX_BMBT_EXTLEN ((xfs_extlen_t)(1ULL << BMBT_BLOCKCOUNT_BITLEN) - 1)
> +#define XFS_MAX_EXTCNT_DATA_FORK ((xfs_extnum_t)0xffffffffffff) /* Unsigned 48-bits */
> +#define XFS_MAX_EXTCNT_ATTR_FORK ((xfs_aextnum_t)0xffffffff) /* Unsigned 32-bits */
> +#define XFS_MAX_EXTCNT_DATA_FORK_OLD ((xfs_extnum_t)0x7fffffff) /* Signed 32-bits */
> +#define XFS_MAX_EXTCNT_ATTR_FORK_OLD ((xfs_aextnum_t)0x7fff) /* Signed 16-bits */
> +
> +#define BMBT_BLOCKCOUNT_MASK XFS_MAX_BMBT_EXTLEN
Would this be simpler if XFS_MAX_EXTCNT* stay where they are, and only
XFS_MAX_BMBT_EXTLEN moves down to be defined as an alias of
BMBT_BLOCKCOUNT_MASK?
--D
>
> /*
> * bmbt records have a file offset (block) field that is 54 bits wide, so this
> diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
> index b8e4e1f69989..780bad03d953 100644
> --- a/fs/xfs/libxfs/xfs_inode_buf.c
> +++ b/fs/xfs/libxfs/xfs_inode_buf.c
> @@ -691,7 +691,7 @@ xfs_inode_validate_extsize(
> if (extsize_bytes % blocksize_bytes)
> return __this_address;
>
> - if (extsize > MAXEXTLEN)
> + if (extsize > XFS_MAX_BMBT_EXTLEN)
> return __this_address;
>
> if (!rt_flag && extsize > mp->m_sb.sb_agblocks / 2)
> @@ -748,7 +748,7 @@ xfs_inode_validate_cowextsize(
> if (cowextsize_bytes % mp->m_sb.sb_blocksize)
> return __this_address;
>
> - if (cowextsize > MAXEXTLEN)
> + if (cowextsize > XFS_MAX_BMBT_EXTLEN)
> return __this_address;
>
> if (cowextsize > mp->m_sb.sb_agblocks / 2)
> diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c
> index 6f83d9b306ee..19313021fb99 100644
> --- a/fs/xfs/libxfs/xfs_trans_resv.c
> +++ b/fs/xfs/libxfs/xfs_trans_resv.c
> @@ -199,8 +199,8 @@ xfs_calc_inode_chunk_res(
> /*
> * Per-extent log reservation for the btree changes involved in freeing or
> * allocating a realtime extent. We have to be able to log as many rtbitmap
> - * blocks as needed to mark inuse MAXEXTLEN blocks' worth of realtime extents,
> - * as well as the realtime summary block.
> + * blocks as needed to mark inuse XFS_BMBT_MAX_EXTLEN blocks' worth of realtime
> + * extents, as well as the realtime summary block.
> */
> static unsigned int
> xfs_rtalloc_log_count(
> @@ -210,7 +210,7 @@ xfs_rtalloc_log_count(
> unsigned int blksz = XFS_FSB_TO_B(mp, 1);
> unsigned int rtbmp_bytes;
>
> - rtbmp_bytes = (MAXEXTLEN / mp->m_sb.sb_rextsize) / NBBY;
> + rtbmp_bytes = (XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize) / NBBY;
> return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
> }
>
> @@ -247,7 +247,7 @@ xfs_rtalloc_log_count(
> * the inode's bmap btree: max depth * block size
> * the agfs of the ags from which the extents are allocated: 2 * sector
> * the superblock free block counter: sector size
> - * the realtime bitmap: ((MAXEXTLEN / rtextsize) / NBBY) bytes
> + * the realtime bitmap: ((XFS_BMBT_MAX_EXTLEN / rtextsize) / NBBY) bytes
> * the realtime summary: 1 block
> * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
> * And the bmap_finish transaction can free bmap blocks in a join (t3):
> @@ -299,7 +299,8 @@ xfs_calc_write_reservation(
> * the agf for each of the ags: 2 * sector size
> * the agfl for each of the ags: 2 * sector size
> * the super block to reflect the freed blocks: sector size
> - * the realtime bitmap: 2 exts * ((MAXEXTLEN / rtextsize) / NBBY) bytes
> + * the realtime bitmap: 2 exts * ((XFS_BMBT_MAX_EXTLEN / rtextsize) / NBBY)
> + * bytes
> * the realtime summary: 2 exts * 1 block
> * worst case split in allocation btrees per extent assuming 2 extents:
> * 2 exts * 2 trees * (2 * max depth - 1) * block size
> diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c
> index a4cbbc346f60..c357593e0a02 100644
> --- a/fs/xfs/scrub/bmap.c
> +++ b/fs/xfs/scrub/bmap.c
> @@ -350,7 +350,7 @@ xchk_bmap_iextent(
> irec->br_startoff);
>
> /* Make sure the extent points to a valid place. */
> - if (irec->br_blockcount > MAXEXTLEN)
> + if (irec->br_blockcount > XFS_MAX_BMBT_EXTLEN)
> xchk_fblock_set_corrupt(info->sc, info->whichfork,
> irec->br_startoff);
> if (info->is_rt &&
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index 73a36b7be3bd..36cde254dedd 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -119,14 +119,14 @@ xfs_bmap_rtalloc(
> */
> ralen = ap->length / mp->m_sb.sb_rextsize;
> /*
> - * If the old value was close enough to MAXEXTLEN that
> + * If the old value was close enough to XFS_BMBT_MAX_EXTLEN that
> * we rounded up to it, cut it back so it's valid again.
> * Note that if it's a really large request (bigger than
> - * MAXEXTLEN), we don't hear about that number, and can't
> + * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't
> * adjust the starting point to match it.
> */
> - if (ralen * mp->m_sb.sb_rextsize >= MAXEXTLEN)
> - ralen = MAXEXTLEN / mp->m_sb.sb_rextsize;
> + if (ralen * mp->m_sb.sb_rextsize >= XFS_MAX_BMBT_EXTLEN)
> + ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize;
>
> /*
> * Lock out modifications to both the RT bitmap and summary inodes
> @@ -840,9 +840,11 @@ xfs_alloc_file_space(
> * count, hence we need to limit the number of blocks we are
> * trying to reserve to avoid an overflow. We can't allocate
> * more than @nimaps extents, and an extent is limited on disk
> - * to MAXEXTLEN (21 bits), so use that to enforce the limit.
> + * to XFS_BMBT_MAX_EXTLEN (21 bits), so use that to enforce the
> + * limit.
> */
> - resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps));
> + resblks = min_t(xfs_fileoff_t, (e - s),
> + (XFS_MAX_BMBT_EXTLEN * nimaps));
> if (unlikely(rt)) {
> dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
> rblocks = resblks;
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index 093758440ad5..6835adc8d62f 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -395,7 +395,7 @@ xfs_iomap_prealloc_size(
> */
> plen = prev.br_blockcount;
> while (xfs_iext_prev_extent(ifp, &ncur, &got)) {
> - if (plen > MAXEXTLEN / 2 ||
> + if (plen > XFS_MAX_BMBT_EXTLEN / 2 ||
> isnullstartblock(got.br_startblock) ||
> got.br_startoff + got.br_blockcount != prev.br_startoff ||
> got.br_startblock + got.br_blockcount != prev.br_startblock)
> @@ -407,23 +407,23 @@ xfs_iomap_prealloc_size(
> /*
> * If the size of the extents is greater than half the maximum extent
> * length, then use the current offset as the basis. This ensures that
> - * for large files the preallocation size always extends to MAXEXTLEN
> - * rather than falling short due to things like stripe unit/width
> - * alignment of real extents.
> + * for large files the preallocation size always extends to
> + * XFS_BMBT_MAX_EXTLEN rather than falling short due to things like stripe
> + * unit/width alignment of real extents.
> */
> alloc_blocks = plen * 2;
> - if (alloc_blocks > MAXEXTLEN)
> + if (alloc_blocks > XFS_MAX_BMBT_EXTLEN)
> alloc_blocks = XFS_B_TO_FSB(mp, offset);
> qblocks = alloc_blocks;
>
> /*
> - * MAXEXTLEN is not a power of two value but we round the prealloc down
> - * to the nearest power of two value after throttling. To prevent the
> - * round down from unconditionally reducing the maximum supported
> - * prealloc size, we round up first, apply appropriate throttling,
> - * round down and cap the value to MAXEXTLEN.
> + * XFS_BMBT_MAX_EXTLEN is not a power of two value but we round the prealloc
> + * down to the nearest power of two value after throttling. To prevent
> + * the round down from unconditionally reducing the maximum supported
> + * prealloc size, we round up first, apply appropriate throttling, round
> + * down and cap the value to XFS_BMBT_MAX_EXTLEN.
> */
> - alloc_blocks = XFS_FILEOFF_MIN(roundup_pow_of_two(MAXEXTLEN),
> + alloc_blocks = XFS_FILEOFF_MIN(roundup_pow_of_two(XFS_MAX_BMBT_EXTLEN),
> alloc_blocks);
>
> freesp = percpu_counter_read_positive(&mp->m_fdblocks);
> @@ -471,14 +471,14 @@ xfs_iomap_prealloc_size(
> */
> if (alloc_blocks)
> alloc_blocks = rounddown_pow_of_two(alloc_blocks);
> - if (alloc_blocks > MAXEXTLEN)
> - alloc_blocks = MAXEXTLEN;
> + if (alloc_blocks > XFS_MAX_BMBT_EXTLEN)
> + alloc_blocks = XFS_MAX_BMBT_EXTLEN;
>
> /*
> * If we are still trying to allocate more space than is
> * available, squash the prealloc hard. This can happen if we
> * have a large file on a small filesystem and the above
> - * lowspace thresholds are smaller than MAXEXTLEN.
> + * lowspace thresholds are smaller than XFS_BMBT_MAX_EXTLEN.
> */
> while (alloc_blocks && alloc_blocks >= freesp)
> alloc_blocks >>= 4;
> --
> 2.30.2
>
next prev parent reply other threads:[~2022-01-05 0:47 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 8:45 [PATCH V4 00/16] xfs: Extend per-inode extent counters Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 01/16] xfs: Move extent count limits to xfs_format.h Chandan Babu R
2022-01-04 23:28 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 02/16] xfs: Introduce xfs_iext_max_nextents() helper Chandan Babu R
2022-01-04 23:30 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 03/16] xfs: Use xfs_extnum_t instead of basic data types Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 04/16] xfs: Introduce xfs_dfork_nextents() helper Chandan Babu R
2022-01-04 23:48 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 05/16] xfs: Use basic types to define xfs_log_dinode's di_nextents and di_anextents Chandan Babu R
2022-01-04 23:50 ` Darrick J. Wong
2022-01-05 13:43 ` Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 06/16] xfs: Promote xfs_extnum_t and xfs_aextnum_t to 64 and 32-bits respectively Chandan Babu R
2021-12-14 14:54 ` kernel test robot
2021-12-14 15:05 ` kernel test robot
2021-12-14 15:15 ` kernel test robot
2021-12-15 9:19 ` Chandan Babu R
2022-01-04 23:54 ` Darrick J. Wong
2022-01-05 14:14 ` Chandan Babu R
2022-01-05 17:21 ` Darrick J. Wong
2022-01-06 7:03 ` Chandan Babu R
2022-01-06 20:31 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 07/16] xfs: Introduce XFS_SB_FEAT_INCOMPAT_NREXT64 and associated per-fs feature bit Chandan Babu R
2022-01-05 0:03 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 08/16] xfs: Introduce XFS_FSOP_GEOM_FLAGS_NREXT64 Chandan Babu R
2022-01-05 0:05 ` Darrick J. Wong
2022-01-05 13:44 ` Chandan Babu R
2022-01-05 17:22 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 09/16] xfs: Introduce XFS_DIFLAG2_NREXT64 and associated helpers Chandan Babu R
2022-01-05 0:43 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 10/16] xfs: Use xfs_rfsblock_t to count maximum blocks that can be used by BMBT Chandan Babu R
2021-12-14 18:15 ` kernel test robot
2021-12-14 8:45 ` [PATCH V4 11/16] xfs: Introduce macros to represent new maximum extent counts for data/attr forks Chandan Babu R
2022-01-05 0:42 ` Darrick J. Wong
2022-01-05 13:46 ` Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 12/16] xfs: Introduce per-inode 64-bit extent counters Chandan Babu R
2022-01-05 1:04 ` Darrick J. Wong
2022-01-05 13:47 ` Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 13/16] xfs: Conditionally upgrade existing inodes to use " Chandan Babu R
2022-01-05 0:18 ` Darrick J. Wong
2022-01-05 13:49 ` Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 14/16] xfs: Enable bulkstat ioctl to support 64-bit per-inode " Chandan Babu R
2022-01-05 0:28 ` Darrick J. Wong
2022-01-05 13:50 ` Chandan Babu R
2021-12-14 8:45 ` [PATCH V4 15/16] xfs: Add XFS_SB_FEAT_INCOMPAT_NREXT64 to the list of supported flags Chandan Babu R
2022-01-05 0:47 ` Darrick J. Wong
2021-12-14 8:45 ` [PATCH V4 16/16] xfs: Define max extent length based on on-disk format definition Chandan Babu R
2022-01-05 0:47 ` Darrick J. Wong [this message]
2022-01-05 13:51 ` Chandan Babu R
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=20220105004706.GT31583@magnolia \
--to=djwong@kernel.org \
--cc=chandan.babu@oracle.com \
--cc=david@fromorbit.com \
--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;
as well as URLs for NNTP newsgroup(s).