diff mbox series

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

Message ID 20231223033703.2949831-3-linan666@huaweicloud.com (mailing list archive)
State Superseded, archived
Headers show
Series md: fix is_mddev_idle() | expand

Commit Message

Li Nan Dec. 23, 2023, 3:37 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

Yu Kuai Jan. 3, 2024, 3:16 a.m. UTC | #1
在 2023/12/23 11:37, linan666@huaweicloud.com 写道:
> 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..e2d03a7a858c 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -584,7 +584,8 @@ extern void mddev_unlock(struct mddev *mddev);
>   
>   static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
>   {
> -	atomic64_add(nr_sectors, &bdev->bd_disk->sync_io);
> +	if (blk_queue_io_stat(bdev->bd_disk->queue))
> +		atomic64_add(nr_sectors, &bdev->bd_disk->sync_io);
>   }
>   
>   static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index a6829ea5b560..b56614eae8dc 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(disk->queue))
> +			continue;

Consider that the queue flag can be set/cleared through sysfs, let's
keep set rdev->last_events in the case 'init'. To prevent a false
positive(althrough highly unlikely) if iostat is enabled during
md_do_sync().

Thanks,
Kuai

> +
>   		curr_events =
>   			(long long)part_stat_read_accum(disk->part0, sectors) -
>   			atomic64_read(&disk->sync_io);
>
Li Nan Jan. 3, 2024, 6:35 a.m. UTC | #2
在 2024/1/3 11:16, Yu Kuai 写道:
> 
> 
> 在 2023/12/23 11:37, linan666@huaweicloud.com 写道:
>> 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..e2d03a7a858c 100644
>> --- a/drivers/md/md.h
>> +++ b/drivers/md/md.h
>> @@ -584,7 +584,8 @@ extern void mddev_unlock(struct mddev *mddev);
>>   static inline void md_sync_acct(struct block_device *bdev, unsigned 
>> long nr_sectors)
>>   {
>> -    atomic64_add(nr_sectors, &bdev->bd_disk->sync_io);
>> +    if (blk_queue_io_stat(bdev->bd_disk->queue))
>> +        atomic64_add(nr_sectors, &bdev->bd_disk->sync_io);
>>   }
>>   static inline void md_sync_acct_bio(struct bio *bio, unsigned long 
>> nr_sectors)
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index a6829ea5b560..b56614eae8dc 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(disk->queue))
>> +            continue;
> 
> Consider that the queue flag can be set/cleared through sysfs, let's
> keep set rdev->last_events in the case 'init'. To prevent a false
> positive(althrough highly unlikely) if iostat is enabled during
> md_do_sync().
> 

Thanks for your review, I will add checks of 'init' in next version.

> Thanks,
> Kuai
> 
>> +
>>           curr_events =
>>               (long long)part_stat_read_accum(disk->part0, sectors) -
>>               atomic64_read(&disk->sync_io);
>>
diff mbox series

Patch

diff --git a/drivers/md/md.h b/drivers/md/md.h
index 1a4f976951c1..e2d03a7a858c 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -584,7 +584,8 @@  extern void mddev_unlock(struct mddev *mddev);
 
 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
 {
-	atomic64_add(nr_sectors, &bdev->bd_disk->sync_io);
+	if (blk_queue_io_stat(bdev->bd_disk->queue))
+		atomic64_add(nr_sectors, &bdev->bd_disk->sync_io);
 }
 
 static inline void md_sync_acct_bio(struct bio *bio, unsigned long nr_sectors)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index a6829ea5b560..b56614eae8dc 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(disk->queue))
+			continue;
+
 		curr_events =
 			(long long)part_stat_read_accum(disk->part0, sectors) -
 			atomic64_read(&disk->sync_io);