* [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 ` Christoph Hellwig
0 siblings, 0 replies; 6+ 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] 6+ messages in thread
* fix block layer bounce buffering for block size > PAGE_SIZE v2
@ 2026-05-07 5:01 Christoph Hellwig
2026-05-07 5:01 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
2026-05-07 5:01 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
0 siblings, 2 replies; 6+ 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
Hi all,
this series has two fixes that make the new block layer bounce
buffering code work for the block size > PAGE_SIZE case.
Changes since v1:
- update a commit log to better describe the applicability
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] 6+ messages in thread
* [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
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-07 11:36 ` Pankaj Raghav (Samsung)
2026-05-07 5:01 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
1 sibling, 1 reply; 6+ 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
When bouncing for block size > PAGE_SIZE file systems that require
file system block size alignment (e.g. zoned XFS), 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] 6+ 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 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
@ 2026-05-07 5:01 ` Christoph Hellwig
1 sibling, 0 replies; 6+ 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] 6+ messages in thread
* Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-05-07 5:01 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
@ 2026-05-07 11:36 ` Pankaj Raghav (Samsung)
2026-05-08 8:12 ` Christoph Hellwig
0 siblings, 1 reply; 6+ messages in thread
From: Pankaj Raghav (Samsung) @ 2026-05-07 11:36 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jens Axboe, Christian Brauner, Darrick J. Wong, linux-block,
linux-xfs, linux-fsdevel
On Thu, May 07, 2026 at 07:01:47AM +0200, Christoph Hellwig wrote:
> When bouncing for block size > PAGE_SIZE file systems that require
> file system block size alignment (e.g. zoned XFS), the bio needs to
> be big enough to fit an entire block.
Not related to the patch but I am wondering why we don't need this for
non-zoned bs > PS configurations.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good.
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
--
Pankaj
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
2026-05-07 11:36 ` Pankaj Raghav (Samsung)
@ 2026-05-08 8:12 ` Christoph Hellwig
0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2026-05-08 8:12 UTC (permalink / raw)
To: Pankaj Raghav (Samsung)
Cc: Christoph Hellwig, Jens Axboe, Christian Brauner, Darrick J. Wong,
linux-block, linux-xfs, linux-fsdevel
On Thu, May 07, 2026 at 01:36:11PM +0200, Pankaj Raghav (Samsung) wrote:
> On Thu, May 07, 2026 at 07:01:47AM +0200, Christoph Hellwig wrote:
> > When bouncing for block size > PAGE_SIZE file systems that require
> > file system block size alignment (e.g. zoned XFS), the bio needs to
> > be big enough to fit an entire block.
>
> Not related to the patch but I am wondering why we don't need this for
> non-zoned bs > PS configurations.
Because they only require sector size alignment for both read and
writes. So I guess we could actually hit it with a large sector size
and not just fs block size.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-08 8:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07 5:01 fix block layer bounce buffering for block size > PAGE_SIZE v2 Christoph Hellwig
2026-05-07 5:01 ` [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce Christoph Hellwig
2026-05-07 11:36 ` Pankaj Raghav (Samsung)
2026-05-08 8:12 ` Christoph Hellwig
2026-05-07 5:01 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2026-04-30 13:20 fix block layer bounce buffering for block size > PAGE_SIZE Christoph Hellwig
2026-04-30 13:20 ` [PATCH 2/2] block: align down bounces bios Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox