Commit 9cfe3dde authored by Keith Busch's avatar Keith Busch Committed by Jens Axboe

block/bounce: count bytes instead of sectors

Individual bv_len's may not be a sector size.
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: default avatarPankaj Raghav <p.raghav@samsung.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220610195830.3574005-8-kbusch@fb.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 67927d22
...@@ -205,19 +205,26 @@ void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig) ...@@ -205,19 +205,26 @@ void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig)
int rw = bio_data_dir(*bio_orig); int rw = bio_data_dir(*bio_orig);
struct bio_vec *to, from; struct bio_vec *to, from;
struct bvec_iter iter; struct bvec_iter iter;
unsigned i = 0; unsigned i = 0, bytes = 0;
bool bounce = false; bool bounce = false;
int sectors = 0; int sectors;
bio_for_each_segment(from, *bio_orig, iter) { bio_for_each_segment(from, *bio_orig, iter) {
if (i++ < BIO_MAX_VECS) if (i++ < BIO_MAX_VECS)
sectors += from.bv_len >> 9; bytes += from.bv_len;
if (PageHighMem(from.bv_page)) if (PageHighMem(from.bv_page))
bounce = true; bounce = true;
} }
if (!bounce) if (!bounce)
return; return;
/*
* Individual bvecs might not be logical block aligned. Round down
* the split size so that each bio is properly block size aligned,
* even if we do not use the full hardware limits.
*/
sectors = ALIGN_DOWN(bytes, queue_logical_block_size(q)) >>
SECTOR_SHIFT;
if (sectors < bio_sectors(*bio_orig)) { if (sectors < bio_sectors(*bio_orig)) {
bio = bio_split(*bio_orig, sectors, GFP_NOIO, &bounce_bio_split); bio = bio_split(*bio_orig, sectors, GFP_NOIO, &bounce_bio_split);
bio_chain(bio, *bio_orig); bio_chain(bio, *bio_orig);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment