blkcg: Track DISCARD statistics and output them in cgroup io.stat
authorTejun Heo <tj@kernel.org>
Wed, 18 Jul 2018 11:47:41 +0000 (04:47 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 18 Jul 2018 14:44:23 +0000 (08:44 -0600)
Add tracking of REQ_OP_DISCARD ios to the per-cgroup io.stat.  Two
fields, dbytes and dios, to respectively count the total bytes and
number of discards are added.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Andy Newell <newella@fb.com>
Cc: Michael Callahan <michaelcallahan@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Documentation/admin-guide/cgroup-v2.rst
block/blk-cgroup.c
include/linux/blk-cgroup.h

index 569ce27b85e53fa7c2e86ab6c781f1f0c9a16afa..3afe10fa82bc69a1919cc42fff1b408a6d86c773 100644 (file)
@@ -1317,17 +1317,19 @@ IO Interface Files
        Lines are keyed by $MAJ:$MIN device numbers and not ordered.
        The following nested keys are defined.
 
-         ======        ===================
+         ======        =====================
          rbytes        Bytes read
          wbytes        Bytes written
          rios          Number of read IOs
          wios          Number of write IOs
-         ======        ===================
+         dbytes        Bytes discarded
+         dios          Number of discard IOs
+         ======        =====================
 
        An example read output follows:
 
-         8:16 rbytes=1459200 wbytes=314773504 rios=192 wios=353
-         8:0 rbytes=90430464 wbytes=299008000 rios=8950 wios=1252
+         8:16 rbytes=1459200 wbytes=314773504 rios=192 wios=353 dbytes=0 dios=0
+         8:0 rbytes=90430464 wbytes=299008000 rios=8950 wios=1252 dbytes=50331648 dios=3021
 
   io.weight
        A read-write flat-keyed file which exists on non-root cgroups.
index 7e2c19ce1a08eea0fd10a533afddda01537ad7fe..1942357d7165d229381a46ec6120380d54b24ed5 100644 (file)
@@ -567,6 +567,7 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
                [BLKG_RWSTAT_WRITE]     = "Write",
                [BLKG_RWSTAT_SYNC]      = "Sync",
                [BLKG_RWSTAT_ASYNC]     = "Async",
+               [BLKG_RWSTAT_DISCARD]   = "Discard",
        };
        const char *dname = blkg_dev_name(pd->blkg);
        u64 v;
@@ -580,7 +581,8 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
                           (unsigned long long)atomic64_read(&rwstat->aux_cnt[i]));
 
        v = atomic64_read(&rwstat->aux_cnt[BLKG_RWSTAT_READ]) +
-               atomic64_read(&rwstat->aux_cnt[BLKG_RWSTAT_WRITE]);
+               atomic64_read(&rwstat->aux_cnt[BLKG_RWSTAT_WRITE]) +
+               atomic64_read(&rwstat->aux_cnt[BLKG_RWSTAT_DISCARD]);
        seq_printf(sf, "%s Total %llu\n", dname, (unsigned long long)v);
        return v;
 }
@@ -959,7 +961,7 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
                const char *dname;
                char *buf;
                struct blkg_rwstat rwstat;
-               u64 rbytes, wbytes, rios, wios;
+               u64 rbytes, wbytes, rios, wios, dbytes, dios;
                size_t size = seq_get_buf(sf, &buf), off = 0;
                int i;
                bool has_stats = false;
@@ -982,19 +984,22 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
                                        offsetof(struct blkcg_gq, stat_bytes));
                rbytes = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_READ]);
                wbytes = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_WRITE]);
+               dbytes = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_DISCARD]);
 
                rwstat = blkg_rwstat_recursive_sum(blkg, NULL,
                                        offsetof(struct blkcg_gq, stat_ios));
                rios = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_READ]);
                wios = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_WRITE]);
+               dios = atomic64_read(&rwstat.aux_cnt[BLKG_RWSTAT_DISCARD]);
 
                spin_unlock_irq(blkg->q->queue_lock);
 
                if (rbytes || wbytes || rios || wios) {
                        has_stats = true;
                        off += scnprintf(buf+off, size-off,
-                                        "rbytes=%llu wbytes=%llu rios=%llu wios=%llu",
-                                        rbytes, wbytes, rios, wios);
+                                        "rbytes=%llu wbytes=%llu rios=%llu wios=%llu dbytes=%llu dios=%llu",
+                                        rbytes, wbytes, rios, wios,
+                                        dbytes, dios);
                }
 
                if (!blkcg_debug_stats)
index de57de4831d5327e52f5d0b8de880c8479533407..3bed5e02a8732f2e1981075e8fc4f28021c4df3b 100644 (file)
@@ -35,6 +35,7 @@ enum blkg_rwstat_type {
        BLKG_RWSTAT_WRITE,
        BLKG_RWSTAT_SYNC,
        BLKG_RWSTAT_ASYNC,
+       BLKG_RWSTAT_DISCARD,
 
        BLKG_RWSTAT_NR,
        BLKG_RWSTAT_TOTAL = BLKG_RWSTAT_NR,
@@ -649,7 +650,9 @@ static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat,
 {
        struct percpu_counter *cnt;
 
-       if (op_is_write(op))
+       if (op_is_discard(op))
+               cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_DISCARD];
+       else if (op_is_write(op))
                cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_WRITE];
        else
                cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_READ];