block/diskstats: accumulate all per-cpu counters in one pass
authorKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Wed, 25 Mar 2020 13:07:06 +0000 (16:07 +0300)
committerJens Axboe <axboe@kernel.dk>
Wed, 25 Mar 2020 14:49:10 +0000 (08:49 -0600)
commitea18e0f0a63af9064db3d4065d90fa743ae0991b
tree8956dcaaaebdac9d91317af6b5d53276c92bbeb0
parent2b8bd423614c595540eaadcfbc702afe8e155e50
block/diskstats: accumulate all per-cpu counters in one pass

Reading /proc/diskstats iterates over all cpus for summing each field.
It's faster to sum all fields in one pass.

Hammering /proc/diskstats with fio shows 2x performance improvement:

fio --name=test --numjobs=$JOBS --filename=/proc/diskstats \
    --size=1k --bs=1k --fallocate=none --create_on_open=1 \
    --time_based=1 --runtime=10 --invalidate=0 --group_report

  JOBS=1 JOBS=10
Before:   7k iops 64k iops
After:  18k iops      120k iops

Also this way code is more compact:

add/remove: 1/0 grow/shrink: 0/2 up/down: 194/-1540 (-1346)
Function                                     old     new   delta
part_stat_read_all                             -     194    +194
diskstats_show                              1344     631    -713
part_stat_show                              1219     392    -827
Total: Before=14966947, After=14965601, chg -0.01%

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c
include/linux/genhd.h