Skip to content

Commit a2f32ee

Browse files
Coly Liaxboe
authored andcommitted
bcache: fix bio_{start,end}_io_acct with proper device
Commit 85750ae ("bcache: use bio_{start,end}_io_acct") moves the io account code to the location after bio_set_dev(bio, dc->bdev) in cached_dev_make_request(). Then the account is performed incorrectly on backing device, indeed the I/O should be counted to bcache device like /dev/bcache0. With the mistaken I/O account, iostat does not display I/O counts for bcache device and all the numbers go to backing device. In writeback mode, the hard drive may have 340K+ IOPS which is impossible and wrong for spinning disk. This patch introduces bch_bio_start_io_acct() and bch_bio_end_io_acct(), which switches bio->bi_disk to bcache device before calling bio_start_io_acct() or bio_end_io_acct(). Now the I/Os are counted to bcache device, and bcache device, cache device and backing device have their correct I/O count information back. Fixes: 85750ae ("bcache: use bio_{start,end}_io_acct") Signed-off-by: Coly Li <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: [email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 4e4d4e0 commit a2f32ee

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

drivers/md/bcache/request.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,28 @@ static void cache_lookup(struct closure *cl)
617617

618618
/* Common code for the make_request functions */
619619

620+
static inline void bch_bio_start_io_acct(struct gendisk *acct_bi_disk,
621+
struct bio *bio,
622+
unsigned long *start_time)
623+
{
624+
struct gendisk *saved_bi_disk = bio->bi_disk;
625+
626+
bio->bi_disk = acct_bi_disk;
627+
*start_time = bio_start_io_acct(bio);
628+
bio->bi_disk = saved_bi_disk;
629+
}
630+
631+
static inline void bch_bio_end_io_acct(struct gendisk *acct_bi_disk,
632+
struct bio *bio,
633+
unsigned long start_time)
634+
{
635+
struct gendisk *saved_bi_disk = bio->bi_disk;
636+
637+
bio->bi_disk = acct_bi_disk;
638+
bio_end_io_acct(bio, start_time);
639+
bio->bi_disk = saved_bi_disk;
640+
}
641+
620642
static void request_endio(struct bio *bio)
621643
{
622644
struct closure *cl = bio->bi_private;
@@ -668,7 +690,7 @@ static void backing_request_endio(struct bio *bio)
668690
static void bio_complete(struct search *s)
669691
{
670692
if (s->orig_bio) {
671-
bio_end_io_acct(s->orig_bio, s->start_time);
693+
bch_bio_end_io_acct(s->d->disk, s->orig_bio, s->start_time);
672694
trace_bcache_request_end(s->d, s->orig_bio);
673695
s->orig_bio->bi_status = s->iop.status;
674696
bio_endio(s->orig_bio);
@@ -728,7 +750,7 @@ static inline struct search *search_alloc(struct bio *bio,
728750
s->recoverable = 1;
729751
s->write = op_is_write(bio_op(bio));
730752
s->read_dirty_data = 0;
731-
s->start_time = bio_start_io_acct(bio);
753+
bch_bio_start_io_acct(d->disk, bio, &s->start_time);
732754

733755
s->iop.c = d->c;
734756
s->iop.bio = NULL;
@@ -1080,7 +1102,7 @@ static void detached_dev_end_io(struct bio *bio)
10801102
bio->bi_end_io = ddip->bi_end_io;
10811103
bio->bi_private = ddip->bi_private;
10821104

1083-
bio_end_io_acct(bio, ddip->start_time);
1105+
bch_bio_end_io_acct(ddip->d->disk, bio, ddip->start_time);
10841106

10851107
if (bio->bi_status) {
10861108
struct cached_dev *dc = container_of(ddip->d,
@@ -1105,7 +1127,8 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio)
11051127
*/
11061128
ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
11071129
ddip->d = d;
1108-
ddip->start_time = bio_start_io_acct(bio);
1130+
bch_bio_start_io_acct(d->disk, bio, &ddip->start_time);
1131+
11091132
ddip->bi_end_io = bio->bi_end_io;
11101133
ddip->bi_private = bio->bi_private;
11111134
bio->bi_end_io = detached_dev_end_io;

0 commit comments

Comments
 (0)