Skip to content

Commit 7be8356

Browse files
YuKuai-huaweiaxboe
authored andcommitted
block: fix that util can be greater than 100%
util means the percentage that disk has IO, and theoretically it should not be greater than 100%. However, there is a gap for rq-based disk: io_ticks will be updated when rq is allocated, however, before such rq dispatch to driver, it will not be account as inflight from blk_mq_start_request() hence diskstats_show()/part_stat_show() will not update io_ticks. For example: 1) at t0, issue a new IO, rq is allocated, and blk_account_io_start() update io_ticks; 2) something is wrong with drivers, and the rq can't be dispatched; 3) at t0 + 10s, drivers recovers and rq is dispatched and done, io_ticks is updated; Then if user is using "iostat 1" to monitor "util", between t0 - t0+9s, util will be zero, and between t0+9s - t0+10s, util will be 1000%. Fix this problem by updating io_ticks from diskstats_show() and part_stat_show() if there are rq allocated. Signed-off-by: Yu Kuai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 99dc422 commit 7be8356

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

block/genhd.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,10 @@ ssize_t part_stat_show(struct device *dev,
951951
struct device_attribute *attr, char *buf)
952952
{
953953
struct block_device *bdev = dev_to_bdev(dev);
954-
struct request_queue *q = bdev_get_queue(bdev);
955954
struct disk_stats stat;
956955
unsigned int inflight;
957956

958-
if (queue_is_mq(q))
959-
inflight = blk_mq_in_flight(q, bdev);
960-
else
961-
inflight = part_in_flight(bdev);
962-
957+
inflight = part_in_flight(bdev);
963958
if (inflight) {
964959
part_stat_lock();
965960
update_io_ticks(bdev, jiffies, true);
@@ -1256,11 +1251,8 @@ static int diskstats_show(struct seq_file *seqf, void *v)
12561251
xa_for_each(&gp->part_tbl, idx, hd) {
12571252
if (bdev_is_partition(hd) && !bdev_nr_sectors(hd))
12581253
continue;
1259-
if (queue_is_mq(gp->queue))
1260-
inflight = blk_mq_in_flight(gp->queue, hd);
1261-
else
1262-
inflight = part_in_flight(hd);
12631254

1255+
inflight = part_in_flight(hd);
12641256
if (inflight) {
12651257
part_stat_lock();
12661258
update_io_ticks(hd, jiffies, true);

0 commit comments

Comments
 (0)