Skip to content

Commit 5b18b5a

Browse files
Mikulas Patockaaxboe
authored andcommitted
block: delete part_round_stats and switch to less precise counting
We want to convert to per-cpu in_flight counters. The function part_round_stats needs the in_flight counter every jiffy, it would be too costly to sum all the percpu variables every jiffy, so it must be deleted. part_round_stats is used to calculate two counters - time_in_queue and io_ticks. time_in_queue can be calculated without part_round_stats, by adding the duration of the I/O when the I/O ends (the value is almost as exact as the previously calculated value, except that time for in-progress I/Os is not counted). io_ticks can be approximated by increasing the value when I/O is started or ended and the jiffies value has changed. If the I/Os take less than a jiffy, the value is as exact as the previously calculated value. If the I/Os take more than a jiffy, io_ticks can drift behind the previously calculated value. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 112f158 commit 5b18b5a

6 files changed

Lines changed: 26 additions & 70 deletions

File tree

‎block/bio.c‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,14 +1664,30 @@ void bio_check_pages_dirty(struct bio *bio)
16641664
}
16651665
EXPORT_SYMBOL_GPL(bio_check_pages_dirty);
16661666

1667+
void update_io_ticks(struct hd_struct *part, unsigned long now)
1668+
{
1669+
unsigned long stamp;
1670+
again:
1671+
stamp = READ_ONCE(part->stamp);
1672+
if (unlikely(stamp != now)) {
1673+
if (likely(cmpxchg(&part->stamp, stamp, now) == stamp)) {
1674+
__part_stat_add(part, io_ticks, 1);
1675+
}
1676+
}
1677+
if (part->partno) {
1678+
part = &part_to_disk(part)->part0;
1679+
goto again;
1680+
}
1681+
}
1682+
16671683
void generic_start_io_acct(struct request_queue *q, int op,
16681684
unsigned long sectors, struct hd_struct *part)
16691685
{
16701686
const int sgrp = op_stat_group(op);
16711687

16721688
part_stat_lock();
16731689

1674-
part_round_stats(q, part);
1690+
update_io_ticks(part, jiffies);
16751691
part_stat_inc(part, ios[sgrp]);
16761692
part_stat_add(part, sectors[sgrp], sectors);
16771693
part_inc_in_flight(q, part, op_is_write(op));
@@ -1683,13 +1699,15 @@ EXPORT_SYMBOL(generic_start_io_acct);
16831699
void generic_end_io_acct(struct request_queue *q, int req_op,
16841700
struct hd_struct *part, unsigned long start_time)
16851701
{
1686-
unsigned long duration = jiffies - start_time;
1702+
unsigned long now = jiffies;
1703+
unsigned long duration = now - start_time;
16871704
const int sgrp = op_stat_group(req_op);
16881705

16891706
part_stat_lock();
16901707

1708+
update_io_ticks(part, now);
16911709
part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration));
1692-
part_round_stats(q, part);
1710+
part_stat_add(part, time_in_queue, duration);
16931711
part_dec_in_flight(q, part, op_is_write(req_op));
16941712

16951713
part_stat_unlock();

‎block/blk-core.c‎

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -584,62 +584,6 @@ struct request *blk_get_request(struct request_queue *q, unsigned int op,
584584
}
585585
EXPORT_SYMBOL(blk_get_request);
586586

587-
static void part_round_stats_single(struct request_queue *q,
588-
struct hd_struct *part, unsigned long now,
589-
unsigned int inflight)
590-
{
591-
if (inflight) {
592-
__part_stat_add(part, time_in_queue,
593-
inflight * (now - part->stamp));
594-
__part_stat_add(part, io_ticks, (now - part->stamp));
595-
}
596-
part->stamp = now;
597-
}
598-
599-
/**
600-
* part_round_stats() - Round off the performance stats on a struct disk_stats.
601-
* @q: target block queue
602-
* @part: target partition
603-
*
604-
* The average IO queue length and utilisation statistics are maintained
605-
* by observing the current state of the queue length and the amount of
606-
* time it has been in this state for.
607-
*
608-
* Normally, that accounting is done on IO completion, but that can result
609-
* in more than a second's worth of IO being accounted for within any one
610-
* second, leading to >100% utilisation. To deal with that, we call this
611-
* function to do a round-off before returning the results when reading
612-
* /proc/diskstats. This accounts immediately for all queue usage up to
613-
* the current jiffies and restarts the counters again.
614-
*/
615-
void part_round_stats(struct request_queue *q, struct hd_struct *part)
616-
{
617-
struct hd_struct *part2 = NULL;
618-
unsigned long now = jiffies;
619-
unsigned int inflight[2];
620-
int stats = 0;
621-
622-
if (part->stamp != now)
623-
stats |= 1;
624-
625-
if (part->partno) {
626-
part2 = &part_to_disk(part)->part0;
627-
if (part2->stamp != now)
628-
stats |= 2;
629-
}
630-
631-
if (!stats)
632-
return;
633-
634-
part_in_flight(q, part, inflight);
635-
636-
if (stats & 2)
637-
part_round_stats_single(q, part2, now, inflight[1]);
638-
if (stats & 1)
639-
part_round_stats_single(q, part, now, inflight[0]);
640-
}
641-
EXPORT_SYMBOL_GPL(part_round_stats);
642-
643587
void blk_put_request(struct request *req)
644588
{
645589
blk_mq_free_request(req);
@@ -1383,9 +1327,10 @@ void blk_account_io_done(struct request *req, u64 now)
13831327
part_stat_lock();
13841328
part = req->part;
13851329

1330+
update_io_ticks(part, jiffies);
13861331
part_stat_inc(part, ios[sgrp]);
13871332
part_stat_add(part, nsecs[sgrp], now - req->start_time_ns);
1388-
part_round_stats(req->q, part);
1333+
part_stat_add(part, time_in_queue, nsecs_to_jiffies64(now - req->start_time_ns));
13891334
part_dec_in_flight(req->q, part, rq_data_dir(req));
13901335

13911336
hd_struct_put(part);
@@ -1420,11 +1365,12 @@ void blk_account_io_start(struct request *rq, bool new_io)
14201365
part = &rq->rq_disk->part0;
14211366
hd_struct_get(part);
14221367
}
1423-
part_round_stats(rq->q, part);
14241368
part_inc_in_flight(rq->q, part, rw);
14251369
rq->part = part;
14261370
}
14271371

1372+
update_io_ticks(part, jiffies);
1373+
14281374
part_stat_unlock();
14291375
}
14301376

‎block/blk-merge.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ static void blk_account_io_merge(struct request *req)
689689
part_stat_lock();
690690
part = req->part;
691691

692-
part_round_stats(req->q, part);
693692
part_dec_in_flight(req->q, part, rq_data_dir(req));
694693

695694
hd_struct_put(part);

‎block/genhd.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,9 +1337,6 @@ static int diskstats_show(struct seq_file *seqf, void *v)
13371337

13381338
disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
13391339
while ((hd = disk_part_iter_next(&piter))) {
1340-
part_stat_lock();
1341-
part_round_stats(gp->queue, hd);
1342-
part_stat_unlock();
13431340
part_in_flight(gp->queue, hd, inflight);
13441341
seq_printf(seqf, "%4d %7d %s "
13451342
"%lu %lu %lu %u "

‎block/partition-generic.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ ssize_t part_stat_show(struct device *dev,
122122
struct request_queue *q = part_to_disk(p)->queue;
123123
unsigned int inflight[2];
124124

125-
part_stat_lock();
126-
part_round_stats(q, p);
127-
part_stat_unlock();
128125
part_in_flight(q, p, inflight);
129126
return sprintf(buf,
130127
"%8lu %8lu %8llu %8u "

‎include/linux/genhd.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ static inline void free_part_info(struct hd_struct *part)
398398
kfree(part->info);
399399
}
400400

401-
/* block/blk-core.c */
402-
extern void part_round_stats(struct request_queue *q, struct hd_struct *part);
401+
void update_io_ticks(struct hd_struct *part, unsigned long now);
403402

404403
/* block/genhd.c */
405404
extern void device_add_disk(struct device *parent, struct gendisk *disk,

0 commit comments

Comments
 (0)