2023-06-21 09:07:49

by Yu Kuai

[permalink] [raw]
Subject: [PATCH v2 0/8] md: fix and refactor io accounting and 'active_io'

From: Yu Kuai <[email protected]>

Changes in v2:
- fix some typos;
- add review tag;

This patchset do following things:
- make io accounting for all raid levels consistent, patch 1, 3-5;
- enable io accounting for all raid levels, patch 6-8;
- hold 'active_io' before io start to dispatch, and release 'active_io'
when io is done, make mddev_suspend() will wait for io to be done, patch 2

This patch set also prepare to synchronize io and raid configuration, make
it possible to use 'active_io' in common layer to judge if normal io is
in flight.

Yu Kuai (8):
md: move initialization and destruction of 'io_acct_set' to md.c
md: also clone new io if io accounting is disabled
raid5: fix missing io accounting in raid5_align_endio()
md/raid1: switch to use md_account_bio() for io accounting
md/raid10: switch to use md_account_bio() for io accounting
md/md-multipath: enable io accounting
md/md-linear: enable io accounting
md/md-faulty: enable io accounting

drivers/md/md-faulty.c | 2 +
drivers/md/md-linear.c | 1 +
drivers/md/md-multipath.c | 1 +
drivers/md/md.c | 78 +++++++++++++++++++--------------------
drivers/md/md.h | 6 +--
drivers/md/raid0.c | 16 +-------
drivers/md/raid1.c | 14 +++----
drivers/md/raid1.h | 1 -
drivers/md/raid10.c | 20 +++++-----
drivers/md/raid10.h | 1 -
drivers/md/raid5.c | 70 ++++++++++-------------------------
11 files changed, 79 insertions(+), 131 deletions(-)

--
2.39.2



2023-06-21 09:10:32

by Yu Kuai

[permalink] [raw]
Subject: [PATCH v2 4/8] md/raid1: switch to use md_account_bio() for io accounting

From: Yu Kuai <[email protected]>

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 <[email protected]>
Reviewed-by: Xiao Ni <[email protected]>
---
drivers/md/raid1.c | 14 ++++++--------
drivers/md/raid1.h | 1 -
2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index dd25832eb045..06fa1580501f 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -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);

diff --git a/drivers/md/raid1.h b/drivers/md/raid1.h
index 468f189da7a0..14d4211a123a 100644
--- a/drivers/md/raid1.h
+++ b/drivers/md/raid1.h
@@ -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
--
2.39.2


2023-06-21 23:45:47

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH v2 0/8] md: fix and refactor io accounting and 'active_io'

On Wed, Jun 21, 2023 at 1:52 AM Yu Kuai <[email protected]> wrote:
>
> From: Yu Kuai <[email protected]>
>
> Changes in v2:
> - fix some typos;
> - add review tag;
>
> This patchset do following things:
> - make io accounting for all raid levels consistent, patch 1, 3-5;
> - enable io accounting for all raid levels, patch 6-8;
> - hold 'active_io' before io start to dispatch, and release 'active_io'
> when io is done, make mddev_suspend() will wait for io to be done, patch 2
>
> This patch set also prepare to synchronize io and raid configuration, make
> it possible to use 'active_io' in common layer to judge if normal io is
> in flight.
>
> Yu Kuai (8):
> md: move initialization and destruction of 'io_acct_set' to md.c
> md: also clone new io if io accounting is disabled
> raid5: fix missing io accounting in raid5_align_endio()
> md/raid1: switch to use md_account_bio() for io accounting
> md/raid10: switch to use md_account_bio() for io accounting
> md/md-multipath: enable io accounting
> md/md-linear: enable io accounting
> md/md-faulty: enable io accounting

Applied to md-next.

Thanks,
Song

>
> drivers/md/md-faulty.c | 2 +
> drivers/md/md-linear.c | 1 +
> drivers/md/md-multipath.c | 1 +
> drivers/md/md.c | 78 +++++++++++++++++++--------------------
> drivers/md/md.h | 6 +--
> drivers/md/raid0.c | 16 +-------
> drivers/md/raid1.c | 14 +++----
> drivers/md/raid1.h | 1 -
> drivers/md/raid10.c | 20 +++++-----
> drivers/md/raid10.h | 1 -
> drivers/md/raid5.c | 70 ++++++++++-------------------------
> 11 files changed, 79 insertions(+), 131 deletions(-)
>
> --
> 2.39.2
>