fix block layer bounce buffering for block size > PAGE_SIZE v2
Subsystems (3)
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(-)
PATCH 1/2 block: pass a minsize argument to bio_iov_iter_bounce
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.
--- block/bio.c | 23 +++++++++++++---------- fs/iomap/direct-io.c | 2 +- include/linux/bio.h | 3 ++- 3 files changed, 16 insertions(+), 12 deletions(-)
block/bio.c +13 -10
@@ -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)
fs/iomap/direct-io.c +1 -1
@@ -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 );
include/linux/bio.h +2 -1
@@ -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,
Signature · 1 line
2.53.0
Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
Quoted 3 lines · Christoph Hellwig
When bouncing for block size >
PAGE_SIZEfile 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.
Quoted 2 lines
Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Signature · 1 line
Pankaj
Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
Quoted 7 lines · Pankaj Raghav (Samsung)
Quoted 3 lines · Christoph Hellwig
When bouncing for block size >
PAGE_SIZEfile 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.
Re: [PATCH 1/2] block: pass a minsize argument to bio_iov_iter_bounce
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
When bouncing for block size >
PAGE_SIZEfile 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 <[email protected]>--- block/bio.c | 23 +++++++++++++---------- fs/iomap/direct-io.c | 2 +- include/linux/bio.h | 3 ++- 3 files changed, 16 insertions(+), 12 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +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
PATCH 2/2 block: align down bounces bios
In reply to Christoph HellwigJust like for the extract user pages path, we need to align down the size to the supported boundary.
--- block/bio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/bio.c +2 -2
@@ -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 ); }/**
Signature · 1 line
2.53.0
Re: [PATCH 2/2] block: align down bounces bios
Quoted 22 lines · Christoph Hellwig
Just like for the extract user pages path, we need to align down the size to the supported boundary.
Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block/bio.c +1
-1@@ -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,
block/bio.c static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter, · line 1389
Quoted 8 lines
block/bio.c +1
-1@@ -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 ); }/**
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +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
Jens Axboe
maintainerQuoted 7 lines · Christoph Hellwig
Hi all,
this series has two fixes that make the new block layer bounce buffering code work for the block size >
PAGE_SIZEcase.Changes since v1:
- update a commit log to better describe the applicability
Can we get some Fixes tags on these, please?
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 10 lines · Jens Axboe
Quoted 7 lines · Christoph Hellwig
Hi all,
this series has two fixes that make the new block layer bounce buffering code work for the block size >
PAGE_SIZEcase.Changes since v1:
- update a commit log to better describe the applicabilityCan we get some Fixes tags on these, please?
Looked myself to not delay this any further, both marked with:
Signature · 1 line
Jens Axboe
Quoted 5 lines · Jens Axboe
Quoted 1 line
Can we get some Fixes tags on these, please?
Looked myself to not delay this any further, both marked with:
Fixes 8dd5e7c75d7b ("block: add helpers to bounce buffer an iov_iter into bios")
Sorry. The tag looks correct.
Quoted 6 lines · Christoph Hellwig
this series has two fixes that make the new block layer bounce buffering code work for the block size >
PAGE_SIZEcase.Changes since v1:
- update a commit log to better describe the applicability
Quoted 7 lines
Diffstat:
block/bio.c | 27 +++++++++++++++------------ fs/iomap/direct-io.c | 2 +- include/linux/bio.h | 3 ++- 3 files changed, 18 insertions(+), 14 deletions(-)[...]
Applied, thanks!
[1/2] block: pass a minsize argument to bio_iov_iter_bounce
commit: 32d5019ed3b6ff4439cb075fb275f655c8a2059c
[2/2] block: align down bounces bios
commit: e7b8b3c5b2a65595d506ffedafac66f0a11fbdc2Best regards,
Signature · 1 line
Jens Axboe