Skip to content

Commit bda9c7d

Browse files
zq-david-wangaxboe
authored andcommitted
block/genhd: use seq_put_decimal_ull for diskstats decimal values
seq_printf is costly. For each block device, 19 decimal values are yielded in /proc/diskstats via seq_printf. On a system with 16 logical block devices, profiling for open/read/close sequences shows seq_printf took ~75% samples of diskstats_show: diskstats_show(92.626% 2269372/2450040) seq_printf(76.026% 1725313/2269372) vsnprintf(99.163% 1710866/1725313) format_decode(26.597% 455040/1710866) number(19.554% 334542/1710866) memcpy_orig(4.183% 71570/1710866) ... srso_return_thunk(0.009% 148/1725313) part_stat_read_all(8.030% 182236/2269372) One million rounds of open/read/close /proc/diskstats takes: real 0m37.687s user 0m0.264s sys 0m32.911s On average, each sequence tooks ~0.032ms With this patch, most decimal values are yield via seq_put_decimal_ull, performance is significantly improved: real 0m20.792s user 0m0.316s sys 0m20.463s On average, each sequence tooks ~0.020ms, a ~37.5% improvement. Signed-off-by: David Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 00e8d29 commit bda9c7d

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

block/genhd.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,40 +1291,35 @@ static int diskstats_show(struct seq_file *seqf, void *v)
12911291
part_stat_unlock();
12921292
}
12931293
part_stat_read_all(hd, &stat);
1294-
seq_printf(seqf, "%4d %7d %pg "
1295-
"%lu %lu %lu %u "
1296-
"%lu %lu %lu %u "
1297-
"%u %u %u "
1298-
"%lu %lu %lu %u "
1299-
"%lu %u"
1300-
"\n",
1301-
MAJOR(hd->bd_dev), MINOR(hd->bd_dev), hd,
1302-
stat.ios[STAT_READ],
1303-
stat.merges[STAT_READ],
1304-
stat.sectors[STAT_READ],
1305-
(unsigned int)div_u64(stat.nsecs[STAT_READ],
1306-
NSEC_PER_MSEC),
1307-
stat.ios[STAT_WRITE],
1308-
stat.merges[STAT_WRITE],
1309-
stat.sectors[STAT_WRITE],
1310-
(unsigned int)div_u64(stat.nsecs[STAT_WRITE],
1311-
NSEC_PER_MSEC),
1312-
inflight,
1313-
jiffies_to_msecs(stat.io_ticks),
1314-
(unsigned int)div_u64(stat.nsecs[STAT_READ] +
1315-
stat.nsecs[STAT_WRITE] +
1316-
stat.nsecs[STAT_DISCARD] +
1317-
stat.nsecs[STAT_FLUSH],
1318-
NSEC_PER_MSEC),
1319-
stat.ios[STAT_DISCARD],
1320-
stat.merges[STAT_DISCARD],
1321-
stat.sectors[STAT_DISCARD],
1322-
(unsigned int)div_u64(stat.nsecs[STAT_DISCARD],
1323-
NSEC_PER_MSEC),
1324-
stat.ios[STAT_FLUSH],
1325-
(unsigned int)div_u64(stat.nsecs[STAT_FLUSH],
1326-
NSEC_PER_MSEC)
1327-
);
1294+
seq_put_decimal_ull_width(seqf, "", MAJOR(hd->bd_dev), 4);
1295+
seq_put_decimal_ull_width(seqf, " ", MINOR(hd->bd_dev), 7);
1296+
seq_printf(seqf, " %pg", hd);
1297+
seq_put_decimal_ull(seqf, " ", stat.ios[STAT_READ]);
1298+
seq_put_decimal_ull(seqf, " ", stat.merges[STAT_READ]);
1299+
seq_put_decimal_ull(seqf, " ", stat.sectors[STAT_READ]);
1300+
seq_put_decimal_ull(seqf, " ", (unsigned int)div_u64(stat.nsecs[STAT_READ],
1301+
NSEC_PER_MSEC));
1302+
seq_put_decimal_ull(seqf, " ", stat.ios[STAT_WRITE]);
1303+
seq_put_decimal_ull(seqf, " ", stat.merges[STAT_WRITE]);
1304+
seq_put_decimal_ull(seqf, " ", stat.sectors[STAT_WRITE]);
1305+
seq_put_decimal_ull(seqf, " ", (unsigned int)div_u64(stat.nsecs[STAT_WRITE],
1306+
NSEC_PER_MSEC));
1307+
seq_put_decimal_ull(seqf, " ", inflight);
1308+
seq_put_decimal_ull(seqf, " ", jiffies_to_msecs(stat.io_ticks));
1309+
seq_put_decimal_ull(seqf, " ", (unsigned int)div_u64(stat.nsecs[STAT_READ] +
1310+
stat.nsecs[STAT_WRITE] +
1311+
stat.nsecs[STAT_DISCARD] +
1312+
stat.nsecs[STAT_FLUSH],
1313+
NSEC_PER_MSEC));
1314+
seq_put_decimal_ull(seqf, " ", stat.ios[STAT_DISCARD]);
1315+
seq_put_decimal_ull(seqf, " ", stat.merges[STAT_DISCARD]);
1316+
seq_put_decimal_ull(seqf, " ", stat.sectors[STAT_DISCARD]);
1317+
seq_put_decimal_ull(seqf, " ", (unsigned int)div_u64(stat.nsecs[STAT_DISCARD],
1318+
NSEC_PER_MSEC));
1319+
seq_put_decimal_ull(seqf, " ", stat.ios[STAT_FLUSH]);
1320+
seq_put_decimal_ull(seqf, " ", (unsigned int)div_u64(stat.nsecs[STAT_FLUSH],
1321+
NSEC_PER_MSEC));
1322+
seq_putc(seqf, '\n');
13281323
}
13291324
rcu_read_unlock();
13301325

0 commit comments

Comments
 (0)