public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>,
	Carlos Maiolino <cem@kernel.org>, Qu Wenruo <wqu@suse.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-block@vger.kernel.org, linux-xfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 01/15] block: add a BIO_MAX_SIZE constant and use it
Date: Mon, 26 Jan 2026 11:36:48 -0800	[thread overview]
Message-ID: <20260126193648.GV5910@frogsfrogsfrogs> (raw)
In-Reply-To: <20260126055406.1421026-2-hch@lst.de>

On Mon, Jan 26, 2026 at 06:53:32AM +0100, Christoph Hellwig wrote:
> Currently the only constant for the maximum bio size is BIO_MAX_SECTORS,
> which is in units of 512-byte sectors, but a lot of user need a byte
> limit.
> 
> Add a BIO_MAX_SIZE constant, redefine BIO_MAX_SECTORS in terms of it, and
> switch all bio-related uses of UINT_MAX for the maximum size to use the
> symbolic names instead.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Yay, thanks!
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  block/bio.c               | 10 +++++-----
>  block/blk-lib.c           |  9 ++++-----
>  block/blk-merge.c         |  8 ++++----
>  include/linux/blk_types.h |  3 ++-
>  4 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index 2359c0723b88..ac7703e149c6 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -924,7 +924,7 @@ static inline bool bio_full(struct bio *bio, unsigned len)
>  {
>  	if (bio->bi_vcnt >= bio->bi_max_vecs)
>  		return true;
> -	if (bio->bi_iter.bi_size > UINT_MAX - len)
> +	if (bio->bi_iter.bi_size > BIO_MAX_SIZE - len)
>  		return true;
>  	return false;
>  }
> @@ -1030,7 +1030,7 @@ int bio_add_page(struct bio *bio, struct page *page,
>  {
>  	if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
>  		return 0;
> -	if (bio->bi_iter.bi_size > UINT_MAX - len)
> +	if (bio->bi_iter.bi_size > BIO_MAX_SIZE - len)
>  		return 0;
>  
>  	if (bio->bi_vcnt > 0) {
> @@ -1057,7 +1057,7 @@ void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
>  {
>  	unsigned long nr = off / PAGE_SIZE;
>  
> -	WARN_ON_ONCE(len > UINT_MAX);
> +	WARN_ON_ONCE(len > BIO_MAX_SIZE);
>  	__bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE);
>  }
>  EXPORT_SYMBOL_GPL(bio_add_folio_nofail);
> @@ -1081,7 +1081,7 @@ bool bio_add_folio(struct bio *bio, struct folio *folio, size_t len,
>  {
>  	unsigned long nr = off / PAGE_SIZE;
>  
> -	if (len > UINT_MAX)
> +	if (len > BIO_MAX_SIZE)
>  		return false;
>  	return bio_add_page(bio, folio_page(folio, nr), len, off % PAGE_SIZE) > 0;
>  }
> @@ -1238,7 +1238,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
>  		extraction_flags |= ITER_ALLOW_P2PDMA;
>  
>  	size = iov_iter_extract_pages(iter, &pages,
> -				      UINT_MAX - bio->bi_iter.bi_size,
> +				      BIO_MAX_SIZE - bio->bi_iter.bi_size,
>  				      nr_pages, extraction_flags, &offset);
>  	if (unlikely(size <= 0))
>  		return size ? size : -EFAULT;
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index 9e2cc58f881f..0be3acdc3eb5 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -32,7 +32,7 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
>  	 * Align the bio size to the discard granularity to make splitting the bio
>  	 * at discard granularity boundaries easier in the driver if needed.
>  	 */
> -	return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT;
> +	return round_down(BIO_MAX_SIZE, discard_granularity) >> SECTOR_SHIFT;
>  }
>  
>  struct bio *blk_alloc_discard_bio(struct block_device *bdev,
> @@ -107,8 +107,7 @@ static sector_t bio_write_zeroes_limit(struct block_device *bdev)
>  {
>  	sector_t bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1;
>  
> -	return min(bdev_write_zeroes_sectors(bdev),
> -		(UINT_MAX >> SECTOR_SHIFT) & ~bs_mask);
> +	return min(bdev_write_zeroes_sectors(bdev), BIO_MAX_SECTORS & ~bs_mask);
>  }
>  
>  /*
> @@ -337,8 +336,8 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
>  	int ret = 0;
>  
>  	/* make sure that "len << SECTOR_SHIFT" doesn't overflow */
> -	if (max_sectors > UINT_MAX >> SECTOR_SHIFT)
> -		max_sectors = UINT_MAX >> SECTOR_SHIFT;
> +	if (max_sectors > BIO_MAX_SECTORS)
> +		max_sectors = BIO_MAX_SECTORS;
>  	max_sectors &= ~bs_mask;
>  
>  	if (max_sectors == 0)
> diff --git a/block/blk-merge.c b/block/blk-merge.c
> index b82c6d304658..0eb0aef97197 100644
> --- a/block/blk-merge.c
> +++ b/block/blk-merge.c
> @@ -95,13 +95,13 @@ static inline bool req_gap_front_merge(struct request *req, struct bio *bio)
>  }
>  
>  /*
> - * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size
> - * is defined as 'unsigned int', meantime it has to be aligned to with the
> + * The maximum size that a bio can fit has to be aligned down to the
>   * logical block size, which is the minimum accepted unit by hardware.
>   */
>  static unsigned int bio_allowed_max_sectors(const struct queue_limits *lim)
>  {
> -	return round_down(UINT_MAX, lim->logical_block_size) >> SECTOR_SHIFT;
> +	return round_down(BIO_MAX_SIZE, lim->logical_block_size) >>
> +			SECTOR_SHIFT;
>  }
>  
>  /*
> @@ -502,7 +502,7 @@ unsigned int blk_recalc_rq_segments(struct request *rq)
>  
>  	rq_for_each_bvec(bv, rq, iter)
>  		bvec_split_segs(&rq->q->limits, &bv, &nr_phys_segs, &bytes,
> -				UINT_MAX, UINT_MAX);
> +				UINT_MAX, BIO_MAX_SIZE);
>  	return nr_phys_segs;
>  }
>  
> diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> index 19a888a2f104..d59553324a84 100644
> --- a/include/linux/blk_types.h
> +++ b/include/linux/blk_types.h
> @@ -281,7 +281,8 @@ struct bio {
>  };
>  
>  #define BIO_RESET_BYTES		offsetof(struct bio, bi_max_vecs)
> -#define BIO_MAX_SECTORS		(UINT_MAX >> SECTOR_SHIFT)
> +#define BIO_MAX_SIZE		UINT_MAX /* max value of bi_iter.bi_size */
> +#define BIO_MAX_SECTORS		(BIO_MAX_SIZE >> SECTOR_SHIFT)
>  
>  static inline struct bio_vec *bio_inline_vecs(struct bio *bio)
>  {
> -- 
> 2.47.3
> 
> 

  parent reply	other threads:[~2026-01-26 19:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26  5:53 bounce buffer direct I/O when stable pages are required v3 Christoph Hellwig
2026-01-26  5:53 ` [PATCH 01/15] block: add a BIO_MAX_SIZE constant and use it Christoph Hellwig
2026-01-26  6:20   ` Damien Le Moal
2026-01-26 10:24   ` Johannes Thumshirn
2026-01-26 10:55   ` Anuj gupta
2026-01-26 19:36   ` Darrick J. Wong [this message]
2026-01-27 14:22   ` Martin K. Petersen
2026-01-26  5:53 ` [PATCH 02/15] block: refactor get_contig_folio_len Christoph Hellwig
2026-01-26 10:59   ` Anuj gupta
2026-01-27 14:24   ` Martin K. Petersen
2026-01-26  5:53 ` [PATCH 03/15] block: open code bio_add_page and fix handling of mismatching P2P ranges Christoph Hellwig
2026-01-27 14:25   ` Martin K. Petersen
2026-01-26  5:53 ` [PATCH 04/15] iov_iter: extract a iov_iter_extract_bvecs helper from bio code Christoph Hellwig
2026-01-26  6:27   ` Damien Le Moal
2026-01-26 11:48     ` Christoph Hellwig
2026-01-27 14:26   ` Martin K. Petersen
2026-01-26  5:53 ` [PATCH 05/15] block: remove bio_release_page Christoph Hellwig
2026-01-27 14:27   ` Martin K. Petersen
2026-01-26  5:53 ` [PATCH 06/15] block: add helpers to bounce buffer an iov_iter into bios Christoph Hellwig
2026-01-26 19:39   ` Darrick J. Wong
2026-01-27 14:29   ` Martin K. Petersen
2026-01-26  5:53 ` [PATCH 07/15] iomap: fix submission side handling of completion side errors Christoph Hellwig
2026-01-26  5:53 ` [PATCH 08/15] iomap: simplify iomap_dio_bio_iter Christoph Hellwig
2026-01-26  5:53 ` [PATCH 09/15] iomap: split out the per-bio logic from iomap_dio_bio_iter Christoph Hellwig
2026-01-26  5:53 ` [PATCH 10/15] iomap: share code between iomap_dio_bio_end_io and iomap_finish_ioend_direct Christoph Hellwig
2026-01-26  5:53 ` [PATCH 11/15] iomap: free the bio before completing the dio Christoph Hellwig
2026-01-26  6:22   ` Damien Le Moal
2026-01-26 11:49     ` Christoph Hellwig
2026-01-26  5:53 ` [PATCH 12/15] iomap: rename IOMAP_DIO_DIRTY to IOMAP_DIO_USER_BACKED Christoph Hellwig
2026-01-26  5:53 ` [PATCH 13/15] iomap: support ioends for direct reads Christoph Hellwig
2026-01-26  5:53 ` [PATCH 14/15] iomap: add a flag to bounce buffer direct I/O Christoph Hellwig
2026-01-26  5:53 ` [PATCH 15/15] xfs: use bounce buffering direct I/O when the device requires stable pages Christoph Hellwig
2026-01-26 10:54 ` bounce buffer direct I/O when stable pages are required v3 Anuj gupta
2026-01-26 12:47   ` Christoph Hellwig
2026-01-28  9:50 ` Carlos Maiolino
2026-01-28 12:17 ` Jens Axboe
2026-01-28 12:17 ` Jens Axboe

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=20260126193648.GV5910@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wqu@suse.com \
    /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