Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

md/raid1: switch to use md_account_bio() for io accounting

Two problems can be fixed this way:

1) 'active_io' will represent inflight io instead of io that is
dispatching.

2) If io accounting is enabled or disabled while io is still inflight,
bio_start_io_acct() and bio_end_io_acct() is not balanced and io
inflight counter will be leaked.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230621165110.1498313-5-yukuai1@huaweicloud.com

authored by

Yu Kuai and committed by
Song Liu
bb2a9ace 05048cbc

+6 -9
+6 -8
drivers/md/raid1.c
··· 304 304 if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) 305 305 bio->bi_status = BLK_STS_IOERR; 306 306 307 - if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue)) 308 - bio_end_io_acct(bio, r1_bio->start_time); 309 307 bio_endio(bio); 310 308 } 311 309 ··· 1301 1303 } 1302 1304 1303 1305 r1_bio->read_disk = rdisk; 1304 - 1305 - if (!r1bio_existed && blk_queue_io_stat(bio->bi_bdev->bd_disk->queue)) 1306 - r1_bio->start_time = bio_start_io_acct(bio); 1307 - 1306 + if (!r1bio_existed) { 1307 + md_account_bio(mddev, &bio); 1308 + r1_bio->master_bio = bio; 1309 + } 1308 1310 read_bio = bio_alloc_clone(mirror->rdev->bdev, bio, gfp, 1309 1311 &mddev->bio_set); 1310 1312 ··· 1498 1500 r1_bio->sectors = max_sectors; 1499 1501 } 1500 1502 1501 - if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue)) 1502 - r1_bio->start_time = bio_start_io_acct(bio); 1503 + md_account_bio(mddev, &bio); 1504 + r1_bio->master_bio = bio; 1503 1505 atomic_set(&r1_bio->remaining, 1); 1504 1506 atomic_set(&r1_bio->behind_remaining, 0); 1505 1507
-1
drivers/md/raid1.h
··· 157 157 sector_t sector; 158 158 int sectors; 159 159 unsigned long state; 160 - unsigned long start_time; 161 160 struct mddev *mddev; 162 161 /* 163 162 * original bio going to /dev/mdx