From 86d7331299fda7634b11c1b7c911432679d525a5 Mon Sep 17 00:00:00 2001
From: Zhang Wensheng <zhangwensheng5@huawei.com>
Date: Thu, 17 Feb 2022 14:42:47 +0800
Subject: [PATCH] block: update io_ticks when io hang
Git-commit: 86d7331299fda7634b11c1b7c911432679d525a5
Patch-mainline: v5.18-rc1
References: bsc#1197817
When the inflight IOs are slow and no new IOs are issued, we expect
iostat could manifest the IO hang problem. However after
commit 5b18b5a73760 ("block: delete part_round_stats and switch to less
precise counting"), io_tick and time_in_queue will not be updated until
the end of IO, and the avgqu-sz and %util columns of iostat will be zero.
Because it has using stat.nsecs accumulation to express time_in_queue
which is not suitable to change, and may %util will express the status
better when io hang occur. To fix io_ticks, we use update_io_ticks and
inflight to update io_ticks when diskstats_show and part_stat_show
been called.
Fixes: 5b18b5a73760 ("block: delete part_round_stats and switch to less precise counting")
Signed-off-by: Zhang Wensheng <zhangwensheng5@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220217064247.4041435-1-zhangwensheng5@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Acked-by: Jan Kara <jack@suse.cz>
---
block/blk-core.c | 2 +-
block/genhd.c | 15 +++++++++++++--
2 files changed, 14 insertions(+), 3 deletions(-)
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1399,7 +1399,7 @@ unsigned int blk_rq_err_bytes(const stru
}
EXPORT_SYMBOL_GPL(blk_rq_err_bytes);
-static void update_io_ticks(struct hd_struct *part, unsigned long now, bool end)
+void update_io_ticks(struct hd_struct *part, unsigned long now, bool end)
{
unsigned long stamp;
again:
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -44,6 +44,7 @@ static void disk_alloc_events(struct gen
static void disk_add_events(struct gendisk *disk);
static void disk_del_events(struct gendisk *disk);
static void disk_release_events(struct gendisk *disk);
+extern void update_io_ticks(struct hd_struct *part, unsigned long now, bool end);
/*
* Set disk capacity and notify if the size is not currently
@@ -1299,12 +1300,17 @@ ssize_t part_stat_show(struct device *de
struct disk_stats stat;
unsigned int inflight;
- part_stat_read_all(p, &stat);
if (queue_is_mq(q))
inflight = blk_mq_in_flight(q, p);
else
inflight = part_in_flight(q, p);
+ if (inflight) {
+ part_stat_lock();
+ update_io_ticks(p, jiffies, true);
+ part_stat_unlock();
+ }
+ part_stat_read_all(p, &stat);
return sprintf(buf,
"%8lu %8lu %8llu %8u "
"%8lu %8lu %8llu %8u "
@@ -1621,12 +1627,17 @@ static int diskstats_show(struct seq_fil
disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
while ((hd = disk_part_iter_next(&piter))) {
- part_stat_read_all(hd, &stat);
if (queue_is_mq(gp->queue))
inflight = blk_mq_in_flight(gp->queue, hd);
else
inflight = part_in_flight(gp->queue, hd);
+ if (inflight) {
+ part_stat_lock();
+ update_io_ticks(hd, jiffies, true);
+ part_stat_unlock();
+ }
+ part_stat_read_all(hd, &stat);
seq_printf(seqf, "%4d %7d %s "
"%lu %lu %lu %u "
"%lu %lu %lu %u "