OSDN Git Service

md/raid1: switch to use md_account_bio() for io accounting
authorYu Kuai <yukuai3@huawei.com>
Wed, 21 Jun 2023 16:51:06 +0000 (00:51 +0800)
committerSong Liu <song@kernel.org>
Thu, 27 Jul 2023 07:13:29 +0000 (00:13 -0700)
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
drivers/md/raid1.c
drivers/md/raid1.h

index dd25832..06fa158 100644 (file)
@@ -304,8 +304,6 @@ static void call_bio_endio(struct r1bio *r1_bio)
        if (!test_bit(R1BIO_Uptodate, &r1_bio->state))
                bio->bi_status = BLK_STS_IOERR;
 
-       if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue))
-               bio_end_io_acct(bio, r1_bio->start_time);
        bio_endio(bio);
 }
 
@@ -1303,10 +1301,10 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
        }
 
        r1_bio->read_disk = rdisk;
-
-       if (!r1bio_existed && blk_queue_io_stat(bio->bi_bdev->bd_disk->queue))
-               r1_bio->start_time = bio_start_io_acct(bio);
-
+       if (!r1bio_existed) {
+               md_account_bio(mddev, &bio);
+               r1_bio->master_bio = bio;
+       }
        read_bio = bio_alloc_clone(mirror->rdev->bdev, bio, gfp,
                                   &mddev->bio_set);
 
@@ -1500,8 +1498,8 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
                r1_bio->sectors = max_sectors;
        }
 
-       if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue))
-               r1_bio->start_time = bio_start_io_acct(bio);
+       md_account_bio(mddev, &bio);
+       r1_bio->master_bio = bio;
        atomic_set(&r1_bio->remaining, 1);
        atomic_set(&r1_bio->behind_remaining, 0);
 
index 468f189..14d4211 100644 (file)
@@ -157,7 +157,6 @@ struct r1bio {
        sector_t                sector;
        int                     sectors;
        unsigned long           state;
-       unsigned long           start_time;
        struct mddev            *mddev;
        /*
         * original bio going to /dev/mdx