提交 74efba23 编写于 作者: Y Yufen Yu 提交者: Yang Yingliang

block: fix inaccurate io_ticks

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: NYufen Yu <yuyufen@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 9c6dea45
...@@ -1675,7 +1675,7 @@ void update_io_ticks(int cpu, struct hd_struct *part, unsigned long now) ...@@ -1675,7 +1675,7 @@ void update_io_ticks(int cpu, struct hd_struct *part, unsigned long now)
stamp = READ_ONCE(part->stamp); stamp = READ_ONCE(part->stamp);
if (unlikely(stamp != now)) { if (unlikely(stamp != now)) {
if (likely(cmpxchg(&part->stamp, stamp, now) == stamp)) 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) { if (part->partno) {
part = &part_to_disk(part)->part0; part = &part_to_disk(part)->part0;
...@@ -1689,7 +1689,7 @@ void generic_start_io_acct(struct request_queue *q, int op, ...@@ -1689,7 +1689,7 @@ void generic_start_io_acct(struct request_queue *q, int op,
const int sgrp = op_stat_group(op); const int sgrp = op_stat_group(op);
int cpu = part_stat_lock(); 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_inc(cpu, part, ios[sgrp]);
part_stat_add(cpu, part, sectors[sgrp], sectors); part_stat_add(cpu, part, sectors[sgrp], sectors);
part_inc_in_flight(q, part, op_is_write(op)); part_inc_in_flight(q, part, op_is_write(op));
......
...@@ -1674,11 +1674,8 @@ static void part_round_stats_single(struct request_queue *q, int cpu, ...@@ -1674,11 +1674,8 @@ static void part_round_stats_single(struct request_queue *q, int cpu,
struct hd_struct *part, unsigned long now, struct hd_struct *part, unsigned long now,
unsigned int inflight) unsigned int inflight)
{ {
if (inflight) { if (inflight)
__part_stat_add(cpu, part, time_in_queue,
inflight * (now - part->stamp));
__part_stat_add(cpu, part, io_ticks, (now - part->stamp)); __part_stat_add(cpu, part, io_ticks, (now - part->stamp));
}
part->stamp = now; part->stamp = now;
} }
...@@ -2791,12 +2788,11 @@ void blk_account_io_start(struct request *rq, bool new_io) ...@@ -2791,12 +2788,11 @@ void blk_account_io_start(struct request *rq, bool new_io)
part_stat_inc(cpu, part, merges[rw]); part_stat_inc(cpu, part, merges[rw]);
} else { } else {
part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq)); 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); part_inc_in_flight(rq->q, part, rw);
rq->part = part; rq->part = part;
} }
update_io_ticks(cpu, part, jiffies);
part_stat_unlock(); part_stat_unlock();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册