* fix block layer bounce buffering for block size > PAGE_SIZE
@ 2026-04-30 13:20 Christoph Hellwig
2026-04-30 13:20 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
2026-04-30 13:20 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
0 siblings, 2 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-04-30 13:20 UTC (permalink / raw)
To: Jens Axboe
Cc: Christian Brauner, Darrick J. Wong, linux-block, linux-xfs,
linux-fsdevel
Hi all,
this series has two fixes that make the new block layer bounce
buffering code work for the block size > PAGE_SIZE case.
Diffstat:
block/bio.c | 27 +++++++++++++++------------
fs/iomap/direct-io.c | 2 +-
include/linux/bio.h | 3 ++-
3 files changed, 18 insertions(+), 14 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-04-30 13:20 fix block layer bounce buffering for block size > PAGE_SIZE Christoph Hellwig
@ 2026-04-30 13:20 ` Christoph Hellwig
2026-04-30 13:30 ` Matthew Wilcox
2026-05-01 12:46 ` Pankaj Raghav (Samsung)
2026-04-30 13:20 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
1 sibling, 2 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-04-30 13:20 UTC (permalink / raw)
To: Jens Axboe
Cc: Christian Brauner, Darrick J. Wong, linux-block, linux-xfs,
linux-fsdevel
When bouncing for block size > PAGE_SIZE file systems, the bio needs to
be big enough to fit an entire block.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/bio.c | 23 +++++++++++++----------
fs/iomap/direct-io.c | 2 +-
include/linux/bio.h | 3 ++-
3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index b8972dba68a0..f3e5d8bea08c 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1279,11 +1279,12 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
return bio_iov_iter_align_down(bio, iter, len_align_mask);
}
-static struct folio *folio_alloc_greedy(gfp_t gfp, size_t *size)
+static struct folio *folio_alloc_greedy(gfp_t gfp, size_t *size,
+ size_t minsize)
{
struct folio *folio;
- while (*size > PAGE_SIZE) {
+ while (*size > minsize) {
folio = folio_alloc(gfp | __GFP_NORETRY, get_order(*size));
if (folio)
return folio;
@@ -1307,7 +1308,7 @@ static void bio_free_folios(struct bio *bio)
}
static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
- size_t maxlen)
+ size_t maxlen, size_t minsize)
{
size_t total_len = min(maxlen, iov_iter_count(iter));
@@ -1322,13 +1323,13 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
size_t this_len = min(total_len, SZ_1M);
struct folio *folio;
- if (this_len > PAGE_SIZE * 2)
+ if (this_len > minsize * 2)
this_len = rounddown_pow_of_two(this_len);
if (bio->bi_iter.bi_size > BIO_MAX_SIZE - this_len)
break;
- folio = folio_alloc_greedy(GFP_KERNEL, &this_len);
+ folio = folio_alloc_greedy(GFP_KERNEL, &this_len, minsize);
if (!folio)
break;
bio_add_folio_nofail(bio, folio, this_len, 0);
@@ -1348,12 +1349,12 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
}
static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
- size_t maxlen)
+ size_t maxlen, size_t minsize)
{
size_t len = min3(iov_iter_count(iter), maxlen, SZ_1M);
struct folio *folio;
- folio = folio_alloc_greedy(GFP_KERNEL, &len);
+ folio = folio_alloc_greedy(GFP_KERNEL, &len, minsize);
if (!folio)
return -ENOMEM;
@@ -1390,6 +1391,7 @@ static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
* @bio: bio to send
* @iter: iter to read from / write into
* @maxlen: maximum size to bounce
+ * @minsize: minimum folio allocation size
*
* Helper for direct I/O implementations that need to bounce buffer because
* we need to checksum the data or perform other operations that require
@@ -1397,11 +1399,12 @@ static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
* copies the data into it. Needs to be paired with bio_iov_iter_unbounce()
* called on completion.
*/
-int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen)
+int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen,
+ size_t minsize)
{
if (op_is_write(bio_op(bio)))
- return bio_iov_iter_bounce_write(bio, iter, maxlen);
- return bio_iov_iter_bounce_read(bio, iter, maxlen);
+ return bio_iov_iter_bounce_write(bio, iter, maxlen, minsize);
+ return bio_iov_iter_bounce_read(bio, iter, maxlen, minsize);
}
static void bvec_unpin(struct bio_vec *bv, bool mark_dirty)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index b0a6549b3848..b36ee619cdcd 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -355,7 +355,7 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
if (dio->flags & IOMAP_DIO_BOUNCE)
ret = bio_iov_iter_bounce(bio, dio->submit.iter,
- iomap_max_bio_size(&iter->iomap));
+ iomap_max_bio_size(&iter->iomap), alignment);
else
ret = bio_iov_iter_get_pages(bio, dio->submit.iter,
alignment - 1);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 97d747320b35..dc17780d6c1e 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -475,7 +475,8 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty);
extern void bio_set_pages_dirty(struct bio *bio);
extern void bio_check_pages_dirty(struct bio *bio);
-int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen);
+int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen,
+ size_t minsize);
void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty);
extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] block: align down bounces bios
2026-04-30 13:20 fix block layer bounce buffering for block size > PAGE_SIZE Christoph Hellwig
2026-04-30 13:20 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
@ 2026-04-30 13:20 ` Christoph Hellwig
1 sibling, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-04-30 13:20 UTC (permalink / raw)
To: Jens Axboe
Cc: Christian Brauner, Darrick J. Wong, linux-block, linux-xfs,
linux-fsdevel
Just like for the extract user pages path, we need to align down the
size to the supported boundary.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/bio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index f3e5d8bea08c..5f10900b3f42 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1345,7 +1345,7 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
if (!bio->bi_iter.bi_size)
return -ENOMEM;
- return 0;
+ return bio_iov_iter_align_down(bio, iter, minsize - 1);
}
static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
@@ -1383,7 +1383,7 @@ static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
bvec_set_folio(&bio->bi_io_vec[0], folio, bio->bi_iter.bi_size, 0);
if (iov_iter_extract_will_pin(iter))
bio_set_flag(bio, BIO_PAGE_PINNED);
- return 0;
+ return bio_iov_iter_align_down(bio, iter, minsize - 1);
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-04-30 13:20 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
@ 2026-04-30 13:30 ` Matthew Wilcox
2026-04-30 14:53 ` Christoph Hellwig
2026-05-01 12:46 ` Pankaj Raghav (Samsung)
1 sibling, 1 reply; 9+ messages in thread
From: Matthew Wilcox @ 2026-04-30 13:30 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jens Axboe, Christian Brauner, Darrick J. Wong, linux-block,
linux-xfs, linux-fsdevel
On Thu, Apr 30, 2026 at 03:20:04PM +0200, Christoph Hellwig wrote:
> -static struct folio *folio_alloc_greedy(gfp_t gfp, size_t *size)
> +static struct folio *folio_alloc_greedy(gfp_t gfp, size_t *size,
> + size_t minsize)
> {
> struct folio *folio;
>
> - while (*size > PAGE_SIZE) {
> + while (*size > minsize) {
> folio = folio_alloc(gfp | __GFP_NORETRY, get_order(*size));
> if (folio)
> return folio;
Seems a bit inefficient. How about something like this:
static struct folio *folio_alloc_greedy(gfp_t gfp, size_t *size, size_t minsize)
{
unsigned int order = get_order(*size);
unsigned int minorder = get_order(minsize);
struct folio *folio;
while (order > minorder) {
folio = folio_alloc(gfp | __GFP_NORETRY, order);
if (folio)
return folio;
order--;
*size = 1UL << order;
}
return folio_alloc(gfp, order);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-04-30 13:30 ` Matthew Wilcox
@ 2026-04-30 14:53 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-04-30 14:53 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Christoph Hellwig, Jens Axboe, Christian Brauner, Darrick J. Wong,
linux-block, linux-xfs, linux-fsdevel
On Thu, Apr 30, 2026 at 02:30:51PM +0100, Matthew Wilcox wrote:
> Seems a bit inefficient. How about something like this:
Works maybe a bit more efficiently, but also is more code and harder
to read. So unless it actualy makes a difference in a relevant way,
why bother?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-04-30 13:20 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
2026-04-30 13:30 ` Matthew Wilcox
@ 2026-05-01 12:46 ` Pankaj Raghav (Samsung)
2026-05-04 4:58 ` Christoph Hellwig
1 sibling, 1 reply; 9+ messages in thread
From: Pankaj Raghav (Samsung) @ 2026-05-01 12:46 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jens Axboe, Christian Brauner, Darrick J. Wong, linux-block,
linux-xfs, linux-fsdevel
On Thu, Apr 30, 2026 at 03:20:04PM +0200, Christoph Hellwig wrote:
> When bouncing for block size > PAGE_SIZE file systems, the bio needs to
> be big enough to fit an entire block.
We set the alignment to fs_block_size when IOMAP_DIO_FSBLOCK_ALIGNED is
set. And we always set IOMAP_DIO_FSBLOCK_ALIGNED in btrfs for dio
reads/writes. IIUC, it was added to support bs > PS block sizes in btrfs.
But in XFS, we set it only for CoW inodes (xfs_is_always_cow_inode is true).
The commit message seems to indicate this is needed for all filesystems
that support bs > PS configurations. Am I missing something here?
Otherwise the patch looks good to me.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> block/bio.c | 23 +++++++++++++----------
> fs/iomap/direct-io.c | 2 +-
> include/linux/bio.h | 3 ++-
> 3 files changed, 16 insertions(+), 12 deletions(-)
>
--
Pankaj
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-05-01 12:46 ` Pankaj Raghav (Samsung)
@ 2026-05-04 4:58 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-05-04 4:58 UTC (permalink / raw)
To: Pankaj Raghav (Samsung)
Cc: Christoph Hellwig, Jens Axboe, Christian Brauner, Darrick J. Wong,
linux-block, linux-xfs, linux-fsdevel
On Fri, May 01, 2026 at 02:46:51PM +0200, Pankaj Raghav (Samsung) wrote:
> On Thu, Apr 30, 2026 at 03:20:04PM +0200, Christoph Hellwig wrote:
> > When bouncing for block size > PAGE_SIZE file systems, the bio needs to
> > be big enough to fit an entire block.
>
> We set the alignment to fs_block_size when IOMAP_DIO_FSBLOCK_ALIGNED is
> set. And we always set IOMAP_DIO_FSBLOCK_ALIGNED in btrfs for dio
> reads/writes. IIUC, it was added to support bs > PS block sizes in btrfs.
> But in XFS, we set it only for CoW inodes (xfs_is_always_cow_inode is true).
Yes, I ran into this with zoned XFS on large block size.
>
> The commit message seems to indicate this is needed for all filesystems
> that support bs > PS configurations. Am I missing something here?
No, the commit message could be a bit more exact.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] block: align down bounces bios
2026-05-07 5:01 fix block layer bounce buffering for block size > PAGE_SIZE v2 Christoph Hellwig
@ 2026-05-07 5:01 ` Christoph Hellwig
2026-05-11 10:40 ` Hannes Reinecke
0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2026-05-07 5:01 UTC (permalink / raw)
To: Jens Axboe
Cc: Christian Brauner, Darrick J. Wong, Pankaj Raghav, linux-block,
linux-xfs, linux-fsdevel
Just like for the extract user pages path, we need to align down the
size to the supported boundary.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/bio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index f3e5d8bea08c..5f10900b3f42 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1345,7 +1345,7 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
if (!bio->bi_iter.bi_size)
return -ENOMEM;
- return 0;
+ return bio_iov_iter_align_down(bio, iter, minsize - 1);
}
static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
@@ -1383,7 +1383,7 @@ static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
bvec_set_folio(&bio->bi_io_vec[0], folio, bio->bi_iter.bi_size, 0);
if (iov_iter_extract_will_pin(iter))
bio_set_flag(bio, BIO_PAGE_PINNED);
- return 0;
+ return bio_iov_iter_align_down(bio, iter, minsize - 1);
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] block: align down bounces bios
2026-05-07 5:01 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
@ 2026-05-11 10:40 ` Hannes Reinecke
0 siblings, 0 replies; 9+ messages in thread
From: Hannes Reinecke @ 2026-05-11 10:40 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Christian Brauner, Darrick J. Wong, Pankaj Raghav, linux-block,
linux-xfs, linux-fsdevel
On 5/7/26 07:01, Christoph Hellwig wrote:
> Just like for the extract user pages path, we need to align down the
> size to the supported boundary.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> block/bio.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index f3e5d8bea08c..5f10900b3f42 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -1345,7 +1345,7 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
>
> if (!bio->bi_iter.bi_size)
> return -ENOMEM;
> - return 0;
> + return bio_iov_iter_align_down(bio, iter, minsize - 1);
> }
>
> static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
> @@ -1383,7 +1383,7 @@ static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
> bvec_set_folio(&bio->bi_io_vec[0], folio, bio->bi_iter.bi_size, 0);
> if (iov_iter_extract_will_pin(iter))
> bio_set_flag(bio, BIO_PAGE_PINNED);
> - return 0;
> + return bio_iov_iter_align_down(bio, iter, minsize - 1);
> }
>
> /**
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-05-11 10:40 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 13:20 fix block layer bounce buffering for block size > PAGE_SIZE Christoph Hellwig
2026-04-30 13:20 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
2026-04-30 13:30 ` Matthew Wilcox
2026-04-30 14:53 ` Christoph Hellwig
2026-05-01 12:46 ` Pankaj Raghav (Samsung)
2026-05-04 4:58 ` Christoph Hellwig
2026-04-30 13:20 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2026-05-07 5:01 fix block layer bounce buffering for block size > PAGE_SIZE v2 Christoph Hellwig
2026-05-07 5:01 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
2026-05-11 10:40 ` Hannes Reinecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox