aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-09-21 19:44:34 -0400
committerJens Axboe <axboe@kernel.dk>2018-09-21 22:26:59 -0400
commitb57e99b4b8b0ebdf9707424e7ddc0c392bdc5fe6 (patch)
tree403679b552a10c8258d4375c561421b367504781
parentd611aaf336b2e8e81f98490eabf7b92889b15319 (diff)
block: use nanosecond resolution for iostat
Klaus Kusche reported that the I/O busy time in /proc/diskstats was not updating properly on 4.18. This is because we started using ktime to track elapsed time, and we convert nanoseconds to jiffies when we update the partition counter. However, this gets rounded down, so any I/Os that take less than a jiffy are not accounted for. Previously in this case, the value of jiffies would sometimes increment while we were doing I/O, so at least some I/Os were accounted for. Let's convert the stats to use nanoseconds internally. We still report milliseconds as before, now more accurately than ever. The value is still truncated to 32 bits for backwards compatibility. Fixes: 522a777566f5 ("block: consolidate struct request timestamp fields") Cc: stable@vger.kernel.org Reported-by: Klaus Kusche <klaus.kusche@computerix.info> Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/bio.c2
-rw-r--r--block/blk-core.c4
-rw-r--r--block/genhd.c6
-rw-r--r--block/partition-generic.c6
-rw-r--r--include/linux/genhd.h5
5 files changed, 12 insertions, 11 deletions
diff --git a/block/bio.c b/block/bio.c
index 8c680a776171..0093bed81c0e 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1684,7 +1684,7 @@ void generic_end_io_acct(struct request_queue *q, int req_op,
1684 const int sgrp = op_stat_group(req_op); 1684 const int sgrp = op_stat_group(req_op);
1685 int cpu = part_stat_lock(); 1685 int cpu = part_stat_lock();
1686 1686
1687 part_stat_add(cpu, part, ticks[sgrp], duration); 1687 part_stat_add(cpu, part, nsecs[sgrp], jiffies_to_nsecs(duration));
1688 part_round_stats(q, cpu, part); 1688 part_round_stats(q, cpu, part);
1689 part_dec_in_flight(q, part, op_is_write(req_op)); 1689 part_dec_in_flight(q, part, op_is_write(req_op));
1690 1690
diff --git a/block/blk-core.c b/block/blk-core.c
index 4dbc93f43b38..cff0a60ee200 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -2733,17 +2733,15 @@ void blk_account_io_done(struct request *req, u64 now)
2733 * containing request is enough. 2733 * containing request is enough.
2734 */ 2734 */
2735 if (blk_do_io_stat(req) && !(req->rq_flags & RQF_FLUSH_SEQ)) { 2735 if (blk_do_io_stat(req) && !(req->rq_flags & RQF_FLUSH_SEQ)) {
2736 unsigned long duration;
2737 const int sgrp = op_stat_group(req_op(req)); 2736 const int sgrp = op_stat_group(req_op(req));
2738 struct hd_struct *part; 2737 struct hd_struct *part;
2739 int cpu; 2738 int cpu;
2740 2739
2741 duration = nsecs_to_jiffies(now - req->start_time_ns);
2742 cpu = part_stat_lock(); 2740 cpu = part_stat_lock();
2743 part = req->part; 2741 part = req->part;
2744 2742
2745 part_stat_inc(cpu, part, ios[sgrp]); 2743 part_stat_inc(cpu, part, ios[sgrp]);
2746 part_stat_add(cpu, part, ticks[sgrp], duration); 2744 part_stat_add(cpu, part, nsecs[sgrp], now - req->start_time_ns);
2747 part_round_stats(req->q, cpu, part); 2745 part_round_stats(req->q, cpu, part);
2748 part_dec_in_flight(req->q, part, rq_data_dir(req)); 2746 part_dec_in_flight(req->q, part, rq_data_dir(req));
2749 2747
diff --git a/block/genhd.c b/block/genhd.c
index 8cc719a37b32..be5bab20b2ab 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1343,18 +1343,18 @@ static int diskstats_show(struct seq_file *seqf, void *v)
1343 part_stat_read(hd, ios[STAT_READ]), 1343 part_stat_read(hd, ios[STAT_READ]),
1344 part_stat_read(hd, merges[STAT_READ]), 1344 part_stat_read(hd, merges[STAT_READ]),
1345 part_stat_read(hd, sectors[STAT_READ]), 1345 part_stat_read(hd, sectors[STAT_READ]),
1346 jiffies_to_msecs(part_stat_read(hd, ticks[STAT_READ])), 1346 (unsigned int)part_stat_read_msecs(hd, STAT_READ),
1347 part_stat_read(hd, ios[STAT_WRITE]), 1347 part_stat_read(hd, ios[STAT_WRITE]),
1348 part_stat_read(hd, merges[STAT_WRITE]), 1348 part_stat_read(hd, merges[STAT_WRITE]),
1349 part_stat_read(hd, sectors[STAT_WRITE]), 1349 part_stat_read(hd, sectors[STAT_WRITE]),
1350 jiffies_to_msecs(part_stat_read(hd, ticks[STAT_WRITE])), 1350 (unsigned int)part_stat_read_msecs(hd, STAT_WRITE),
1351 inflight[0], 1351 inflight[0],
1352 jiffies_to_msecs(part_stat_read(hd, io_ticks)), 1352 jiffies_to_msecs(part_stat_read(hd, io_ticks)),
1353 jiffies_to_msecs(part_stat_read(hd, time_in_queue)), 1353 jiffies_to_msecs(part_stat_read(hd, time_in_queue)),
1354 part_stat_read(hd, ios[STAT_DISCARD]), 1354 part_stat_read(hd, ios[STAT_DISCARD]),
1355 part_stat_read(hd, merges[STAT_DISCARD]), 1355 part_stat_read(hd, merges[STAT_DISCARD]),
1356 part_stat_read(hd, sectors[STAT_DISCARD]), 1356 part_stat_read(hd, sectors[STAT_DISCARD]),
1357 jiffies_to_msecs(part_stat_read(hd, ticks[STAT_DISCARD])) 1357 (unsigned int)part_stat_read_msecs(hd, STAT_DISCARD)
1358 ); 1358 );
1359 } 1359 }
1360 disk_part_iter_exit(&piter); 1360 disk_part_iter_exit(&piter);
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 5a8975a1201c..d3d14e81fb12 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -136,18 +136,18 @@ ssize_t part_stat_show(struct device *dev,
136 part_stat_read(p, ios[STAT_READ]), 136 part_stat_read(p, ios[STAT_READ]),
137 part_stat_read(p, merges[STAT_READ]), 137 part_stat_read(p, merges[STAT_READ]),
138 (unsigned long long)part_stat_read(p, sectors[STAT_READ]), 138 (unsigned long long)part_stat_read(p, sectors[STAT_READ]),
139 jiffies_to_msecs(part_stat_read(p, ticks[STAT_READ])), 139 (unsigned int)part_stat_read_msecs(p, STAT_READ),
140 part_stat_read(p, ios[STAT_WRITE]), 140 part_stat_read(p, ios[STAT_WRITE]),
141 part_stat_read(p, merges[STAT_WRITE]), 141 part_stat_read(p, merges[STAT_WRITE]),
142 (unsigned long long)part_stat_read(p, sectors[STAT_WRITE]), 142 (unsigned long long)part_stat_read(p, sectors[STAT_WRITE]),
143 jiffies_to_msecs(part_stat_read(p, ticks[STAT_WRITE])), 143 (unsigned int)part_stat_read_msecs(p, STAT_WRITE),
144 inflight[0], 144 inflight[0],
145 jiffies_to_msecs(part_stat_read(p, io_ticks)), 145 jiffies_to_msecs(part_stat_read(p, io_ticks)),
146 jiffies_to_msecs(part_stat_read(p, time_in_queue)), 146 jiffies_to_msecs(part_stat_read(p, time_in_queue)),
147 part_stat_read(p, ios[STAT_DISCARD]), 147 part_stat_read(p, ios[STAT_DISCARD]),
148 part_stat_read(p, merges[STAT_DISCARD]), 148 part_stat_read(p, merges[STAT_DISCARD]),
149 (unsigned long long)part_stat_read(p, sectors[STAT_DISCARD]), 149 (unsigned long long)part_stat_read(p, sectors[STAT_DISCARD]),
150 jiffies_to_msecs(part_stat_read(p, ticks[STAT_DISCARD]))); 150 (unsigned int)part_stat_read_msecs(p, STAT_DISCARD));
151} 151}
152 152
153ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr, 153ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 57864422a2c8..25c08c6c7f99 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -83,10 +83,10 @@ struct partition {
83} __attribute__((packed)); 83} __attribute__((packed));
84 84
85struct disk_stats { 85struct disk_stats {
86 u64 nsecs[NR_STAT_GROUPS];
86 unsigned long sectors[NR_STAT_GROUPS]; 87 unsigned long sectors[NR_STAT_GROUPS];
87 unsigned long ios[NR_STAT_GROUPS]; 88 unsigned long ios[NR_STAT_GROUPS];
88 unsigned long merges[NR_STAT_GROUPS]; 89 unsigned long merges[NR_STAT_GROUPS];
89 unsigned long ticks[NR_STAT_GROUPS];
90 unsigned long io_ticks; 90 unsigned long io_ticks;
91 unsigned long time_in_queue; 91 unsigned long time_in_queue;
92}; 92};
@@ -354,6 +354,9 @@ static inline void free_part_stats(struct hd_struct *part)
354 354
355#endif /* CONFIG_SMP */ 355#endif /* CONFIG_SMP */
356 356
357#define part_stat_read_msecs(part, which) \
358 div_u64(part_stat_read(part, nsecs[which]), NSEC_PER_MSEC)
359
357#define part_stat_read_accum(part, field) \ 360#define part_stat_read_accum(part, field) \
358 (part_stat_read(part, field[STAT_READ]) + \ 361 (part_stat_read(part, field[STAT_READ]) + \
359 part_stat_read(part, field[STAT_WRITE]) + \ 362 part_stat_read(part, field[STAT_WRITE]) + \