block: Track DISCARD statistics and output them in stat and diskstat

Add tracking of REQ_OP_DISCARD ios to the partition statistics and
append them to the various stat files in /sys as well as
/proc/diskstats.  These are tracked with the same four stats as reads
and writes:

Number of discard ios completed.
Number of discard ios merged
Number of discard sectors completed
Milliseconds spent on discard requests

This is done via adding a new STAT_DISCARD define to genhd.h and then
using it to index that stat field for discard requests.

tj: Refreshed on top of v4.17 and other previous updates.

Signed-off-by: Michael Callahan <michaelcallahan@fb.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Andy Newell <newella@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Michael Callahan
2018-07-18 04:47:40 -07:00
committed by Jens Axboe
parent ddcf35d397
commit bdca3c87fb
7 changed files with 68 additions and 18 deletions

View File

@@ -360,6 +360,7 @@ enum req_flag_bits {
enum stat_group {
STAT_READ,
STAT_WRITE,
STAT_DISCARD,
NR_STAT_GROUPS
};
@@ -401,8 +402,15 @@ static inline bool op_is_sync(unsigned int op)
(op & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH));
}
static inline bool op_is_discard(unsigned int op)
{
return (op & REQ_OP_MASK) == REQ_OP_DISCARD;
}
static inline int op_stat_group(unsigned int op)
{
if (op_is_discard(op))
return STAT_DISCARD;
return op_is_write(op);
}

View File

@@ -356,7 +356,8 @@ static inline void free_part_stats(struct hd_struct *part)
#define part_stat_read_accum(part, field) \
(part_stat_read(part, field[STAT_READ]) + \
part_stat_read(part, field[STAT_WRITE]))
part_stat_read(part, field[STAT_WRITE]) + \
part_stat_read(part, field[STAT_DISCARD]))
#define part_stat_add(cpu, part, field, addnd) do { \
__part_stat_add((cpu), (part), field, addnd); \