Skip to content

Commit 51d798c

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: change the blk_queue_bounce calling convention
The double indirect bio leads to somewhat suboptimal code generation. Instead return the (original or split) bio, and make sure the request_queue arguments to the lower level helpers is passed after the bio to avoid constant reshuffling of the argument passing registers. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20220727162300.3089193-3-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5a97806 commit 51d798c

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ void blk_mq_submit_bio(struct bio *bio)
28152815
unsigned int nr_segs = 1;
28162816
blk_status_t ret;
28172817

2818-
blk_queue_bounce(q, &bio);
2818+
bio = blk_queue_bounce(bio, q);
28192819
if (bio_may_exceed_limits(bio, q))
28202820
bio = __bio_split_to_limits(bio, q, &nr_segs);
28212821

block/blk.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static inline void blk_throtl_bio_endio(struct bio *bio) { }
378378
static inline void blk_throtl_stat_add(struct request *rq, u64 time) { }
379379
#endif
380380

381-
void __blk_queue_bounce(struct request_queue *q, struct bio **bio);
381+
struct bio *__blk_queue_bounce(struct bio *bio, struct request_queue *q);
382382

383383
static inline bool blk_queue_may_bounce(struct request_queue *q)
384384
{
@@ -387,10 +387,12 @@ static inline bool blk_queue_may_bounce(struct request_queue *q)
387387
max_low_pfn >= max_pfn;
388388
}
389389

390-
static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
390+
static inline struct bio *blk_queue_bounce(struct bio *bio,
391+
struct request_queue *q)
391392
{
392-
if (unlikely(blk_queue_may_bounce(q) && bio_has_data(*bio)))
393-
__blk_queue_bounce(q, bio);
393+
if (unlikely(blk_queue_may_bounce(q) && bio_has_data(bio)))
394+
return __blk_queue_bounce(bio, q);
395+
return bio;
394396
}
395397

396398
#ifdef CONFIG_BLK_CGROUP_IOLATENCY

block/bounce.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,24 +199,24 @@ static struct bio *bounce_clone_bio(struct bio *bio_src)
199199
return NULL;
200200
}
201201

202-
void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig)
202+
struct bio *__blk_queue_bounce(struct bio *bio_orig, struct request_queue *q)
203203
{
204204
struct bio *bio;
205-
int rw = bio_data_dir(*bio_orig);
205+
int rw = bio_data_dir(bio_orig);
206206
struct bio_vec *to, from;
207207
struct bvec_iter iter;
208208
unsigned i = 0, bytes = 0;
209209
bool bounce = false;
210210
int sectors;
211211

212-
bio_for_each_segment(from, *bio_orig, iter) {
212+
bio_for_each_segment(from, bio_orig, iter) {
213213
if (i++ < BIO_MAX_VECS)
214214
bytes += from.bv_len;
215215
if (PageHighMem(from.bv_page))
216216
bounce = true;
217217
}
218218
if (!bounce)
219-
return;
219+
return bio_orig;
220220

221221
/*
222222
* Individual bvecs might not be logical block aligned. Round down
@@ -225,13 +225,13 @@ void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig)
225225
*/
226226
sectors = ALIGN_DOWN(bytes, queue_logical_block_size(q)) >>
227227
SECTOR_SHIFT;
228-
if (sectors < bio_sectors(*bio_orig)) {
229-
bio = bio_split(*bio_orig, sectors, GFP_NOIO, &bounce_bio_split);
230-
bio_chain(bio, *bio_orig);
231-
submit_bio_noacct(*bio_orig);
232-
*bio_orig = bio;
228+
if (sectors < bio_sectors(bio_orig)) {
229+
bio = bio_split(bio_orig, sectors, GFP_NOIO, &bounce_bio_split);
230+
bio_chain(bio, bio_orig);
231+
submit_bio_noacct(bio_orig);
232+
bio_orig = bio;
233233
}
234-
bio = bounce_clone_bio(*bio_orig);
234+
bio = bounce_clone_bio(bio_orig);
235235

236236
/*
237237
* Bvec table can't be updated by bio_for_each_segment_all(),
@@ -254,7 +254,7 @@ void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig)
254254
to->bv_page = bounce_page;
255255
}
256256

257-
trace_block_bio_bounce(*bio_orig);
257+
trace_block_bio_bounce(bio_orig);
258258

259259
bio->bi_flags |= (1 << BIO_BOUNCED);
260260

@@ -263,6 +263,6 @@ void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig)
263263
else
264264
bio->bi_end_io = bounce_end_io_write;
265265

266-
bio->bi_private = *bio_orig;
267-
*bio_orig = bio;
266+
bio->bi_private = bio_orig;
267+
return bio;
268268
}

0 commit comments

Comments
 (0)