Skip to content

Commit b5af37a

Browse files
koct9iaxboe
authored andcommitted
block: add a blk_account_io_merge_bio helper
Move the non-"new_io" branch of blk_account_io_start() into separate function. Fix merge accounting for discards (they were counted as write merges). The new blk_account_io_merge_bio() doesn't call update_io_ticks() unlike blk_account_io_start(), as there is no reason for that. [hch: rebased] Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b9c54f5 commit b5af37a

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎block/blk-core.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,16 @@ void blk_put_request(struct request *req)
636636
}
637637
EXPORT_SYMBOL(blk_put_request);
638638

639+
static void blk_account_io_merge_bio(struct request *req)
640+
{
641+
if (!blk_do_io_stat(req))
642+
return;
643+
644+
part_stat_lock();
645+
part_stat_inc(req->part, merges[op_stat_group(req_op(req))]);
646+
part_stat_unlock();
647+
}
648+
639649
bool bio_attempt_back_merge(struct request *req, struct bio *bio,
640650
unsigned int nr_segs)
641651
{
@@ -656,7 +666,7 @@ bool bio_attempt_back_merge(struct request *req, struct bio *bio,
656666

657667
bio_crypt_free_ctx(bio);
658668

659-
blk_account_io_start(req, false);
669+
blk_account_io_merge_bio(req);
660670
return true;
661671
}
662672

@@ -682,7 +692,7 @@ bool bio_attempt_front_merge(struct request *req, struct bio *bio,
682692

683693
bio_crypt_do_front_merge(req, bio);
684694

685-
blk_account_io_start(req, false);
695+
blk_account_io_merge_bio(req);
686696
return true;
687697
}
688698

@@ -704,7 +714,7 @@ bool bio_attempt_discard_merge(struct request_queue *q, struct request *req,
704714
req->__data_len += bio->bi_iter.bi_size;
705715
req->nr_phys_segments = segments + 1;
706716

707-
blk_account_io_start(req, false);
717+
blk_account_io_merge_bio(req);
708718
return true;
709719
no_merge:
710720
req_set_nomerge(q, req);
@@ -1329,7 +1339,7 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
13291339
return BLK_STS_IOERR;
13301340

13311341
if (blk_queue_io_stat(q))
1332-
blk_account_io_start(rq, true);
1342+
blk_account_io_start(rq);
13331343

13341344
/*
13351345
* Since we have a scheduler attached on the top device,
@@ -1433,16 +1443,13 @@ void blk_account_io_done(struct request *req, u64 now)
14331443
}
14341444
}
14351445

1436-
void blk_account_io_start(struct request *rq, bool new_io)
1446+
void blk_account_io_start(struct request *rq)
14371447
{
14381448
if (!blk_do_io_stat(rq))
14391449
return;
14401450

14411451
part_stat_lock();
1442-
if (!new_io)
1443-
part_stat_inc(rq->part, merges[rq_data_dir(rq)]);
1444-
else
1445-
rq->part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
1452+
rq->part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
14461453
update_io_ticks(rq->part, jiffies, false);
14471454
part_stat_unlock();
14481455
}

‎block/blk-exec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
5555
rq->rq_disk = bd_disk;
5656
rq->end_io = done;
5757

58-
blk_account_io_start(rq, true);
58+
blk_account_io_start(rq);
5959

6060
/*
6161
* don't check dying flag for MQ because the request won't

‎block/blk-mq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio,
18221822
blk_rq_bio_prep(rq, bio, nr_segs);
18231823
blk_crypto_rq_bio_prep(rq, bio, GFP_NOIO);
18241824

1825-
blk_account_io_start(rq, true);
1825+
blk_account_io_start(rq);
18261826
}
18271827

18281828
static blk_status_t __blk_mq_issue_directly(struct blk_mq_hw_ctx *hctx,

‎block/blk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ bool bio_attempt_discard_merge(struct request_queue *q, struct request *req,
185185
bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
186186
unsigned int nr_segs, struct request **same_queue_rq);
187187

188-
void blk_account_io_start(struct request *req, bool new_io);
188+
void blk_account_io_start(struct request *req);
189189
void blk_account_io_done(struct request *req, u64 now);
190190

191191
/*

0 commit comments

Comments
 (0)