[v2,2/2] md: don't account sync_io if iostats of the disk is disabled

Message ID 20231215013931.3329455-3-linan666@huaweicloud.com
State New
Headers
Series md: fix is_mddev_idle() |

Commit Message

Li Nan Dec. 15, 2023, 1:39 a.m. UTC
  From: Li Nan <linan122@huawei.com>

If iostats is disabled, disk_stats will not be updated and
part_stat_read_accum() only returns a constant value. In this case,
continuing to count sync_io and to check is_mddev_idle() is no longer
meaningful.

Signed-off-by: Li Nan <linan122@huawei.com>
---
 drivers/md/md.h | 3 ++-
 drivers/md/md.c | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
  

Comments

Song Liu Dec. 15, 2023, 9:08 a.m. UTC | #1
On Thu, Dec 14, 2023 at 5:41 PM <linan666@huaweicloud.com> wrote:
>
> From: Li Nan <linan122@huawei.com>
>
> If iostats is disabled, disk_stats will not be updated and
> part_stat_read_accum() only returns a constant value. In this case,
> continuing to count sync_io and to check is_mddev_idle() is no longer
> meaningful.
>
> Signed-off-by: Li Nan <linan122@huawei.com>
> ---
>  drivers/md/md.h | 3 ++-
>  drivers/md/md.c | 4 ++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index 1a4f976951c1..75f5c5d04e71 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -589,7 +589,8 @@ static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sect
>
>  static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)
>  {
> -       md_sync_acct(bio->bi_bdev, nr_sectors);
> +       if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue))
> +               md_sync_acct(bio->bi_bdev, nr_sectors);

Do we need the same check for md_sync_acct()?

>  }
>
>  struct md_personality
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 1d71b2a9af03..18bbceb0ffd6 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -8502,6 +8502,10 @@ static int is_mddev_idle(struct mddev *mddev, int init)
>         rcu_read_lock();
>         rdev_for_each_rcu(rdev, mddev) {
>                 struct gendisk *disk = rdev->bdev->bd_disk;
> +
> +               if (blk_queue_io_stat(mddev->queue))
> +                       continue;

This looks weird. Do you mean

   if (!blk_queue_io_stat(disk->queue))

Note that I changed two things here: 1) add "!"; 2) check disk, not mddev.

Did I miss something?

Thanks,
Song

> +
>                 curr_events =
>                         (long long)part_stat_read_accum(disk->part0, sectors) -
>                               atomic64_read(&disk->sync_io);
> --
> 2.39.2
>
  
Li Nan Dec. 15, 2023, 9:29 a.m. UTC | #2
在 2023/12/15 17:08, Song Liu 写道:
> On Thu, Dec 14, 2023 at 5:41 PM <linan666@huaweicloud.com> wrote:
>>
>> From: Li Nan <linan122@huawei.com>
>>
>> If iostats is disabled, disk_stats will not be updated and
>> part_stat_read_accum() only returns a constant value. In this case,
>> continuing to count sync_io and to check is_mddev_idle() is no longer
>> meaningful.
>>
>> Signed-off-by: Li Nan <linan122@huawei.com>
>> ---
>>   drivers/md/md.h | 3 ++-
>>   drivers/md/md.c | 4 ++++
>>   2 files changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/md/md.h b/drivers/md/md.h
>> index 1a4f976951c1..75f5c5d04e71 100644
>> --- a/drivers/md/md.h
>> +++ b/drivers/md/md.h
>> @@ -589,7 +589,8 @@ static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sect
>>
>>   static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)
>>   {
>> -       md_sync_acct(bio->bi_bdev, nr_sectors);
>> +       if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue))
>> +               md_sync_acct(bio->bi_bdev, nr_sectors);
> 
> Do we need the same check for md_sync_acct()?
> 
>>   }
>>
>>   struct md_personality
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index 1d71b2a9af03..18bbceb0ffd6 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -8502,6 +8502,10 @@ static int is_mddev_idle(struct mddev *mddev, int init)
>>          rcu_read_lock();
>>          rdev_for_each_rcu(rdev, mddev) {
>>                  struct gendisk *disk = rdev->bdev->bd_disk;
>> +
>> +               if (blk_queue_io_stat(mddev->queue))
>> +                       continue;
> 
> This looks weird. Do you mean
> 
>     if (!blk_queue_io_stat(disk->queue))
> 
> Note that I changed two things here: 1) add "!"; 2) check disk, not mddev.
> 
> Did I miss something?
> 
> Thanks,
> Song
> 

Yeah... It's my bad. I will fix it in v3.

>> +
>>                  curr_events =
>>                          (long long)part_stat_read_accum(disk->part0, sectors) -
>>                                atomic64_read(&disk->sync_io);
>> --
>> 2.39.2
>>
> 
> .
  

Patch

diff --git a/drivers/md/md.h b/drivers/md/md.h
index 1a4f976951c1..75f5c5d04e71 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -589,7 +589,8 @@  static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sect
 
 static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)
 {
-	md_sync_acct(bio->bi_bdev, nr_sectors);
+	if (blk_queue_io_stat(bio->bi_bdev->bd_disk->queue))
+		md_sync_acct(bio->bi_bdev, nr_sectors);
 }
 
 struct md_personality
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 1d71b2a9af03..18bbceb0ffd6 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -8502,6 +8502,10 @@  static int is_mddev_idle(struct mddev *mddev, int init)
 	rcu_read_lock();
 	rdev_for_each_rcu(rdev, mddev) {
 		struct gendisk *disk = rdev->bdev->bd_disk;
+
+		if (blk_queue_io_stat(mddev->queue))
+			continue;
+
 		curr_events =
 			(long long)part_stat_read_accum(disk->part0, sectors) -
 			      atomic64_read(&disk->sync_io);