From: Yufen Yu yuyufen@huawei.com
hulk inclusion category: bugfix bugzilla: 31388 CVE: NA ---------------------------
After introducing commit 5b18b5a73760 ("block: delete part_round_stats and switch to less precise counting"), '%util' accounted by iostat will be over reality data. In fact, the device is quite idle, but iostat may show '%util' as a big number (e.g. 50%). It can produce by fio:
fio --name=1 --direct=1 --bs=4k --rw=read --filename=/dev/sda \ --thinktime=4ms --runtime=180
We fix this by reserving part_round_stats() in io start path.
fixes: 5b18b5a73760 ("block: delete part_round_stats and switch to less precise counting") Signed-off-by: Yufen Yu yuyufen@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- block/bio.c | 4 ++-- block/blk-core.c | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/block/bio.c b/block/bio.c index 48a8cf5..94d0f47 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1675,7 +1675,7 @@ void update_io_ticks(int cpu, struct hd_struct *part, unsigned long now) stamp = READ_ONCE(part->stamp); if (unlikely(stamp != now)) { if (likely(cmpxchg(&part->stamp, stamp, now) == stamp)) - __part_stat_add(cpu, part, io_ticks, 1); + __part_stat_add(cpu, part, io_ticks, now - stamp); } if (part->partno) { part = &part_to_disk(part)->part0; @@ -1689,7 +1689,7 @@ void generic_start_io_acct(struct request_queue *q, int op, const int sgrp = op_stat_group(op); int cpu = part_stat_lock();
- update_io_ticks(cpu, part, jiffies); + part_round_stats(q, cpu, part); part_stat_inc(cpu, part, ios[sgrp]); part_stat_add(cpu, part, sectors[sgrp], sectors); part_inc_in_flight(q, part, op_is_write(op)); diff --git a/block/blk-core.c b/block/blk-core.c index d9e3ee6..7afe44d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1674,11 +1674,8 @@ static void part_round_stats_single(struct request_queue *q, int cpu, struct hd_struct *part, unsigned long now, unsigned int inflight) { - if (inflight) { - __part_stat_add(cpu, part, time_in_queue, - inflight * (now - part->stamp)); + if (inflight) __part_stat_add(cpu, part, io_ticks, (now - part->stamp)); - } part->stamp = now; }
@@ -2791,12 +2788,11 @@ void blk_account_io_start(struct request *rq, bool new_io) part_stat_inc(cpu, part, merges[rw]); } else { part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq)); + part_round_stats(rq->q, cpu, part); part_inc_in_flight(rq->q, part, rw); rq->part = part; }
- update_io_ticks(cpu, part, jiffies); - part_stat_unlock(); }