block: Define and use STAT_READ and STAT_WRITE
authorMichael Callahan <michaelcallahan@fb.com>
Wed, 18 Jul 2018 11:47:38 +0000 (04:47 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 18 Jul 2018 14:44:18 +0000 (08:44 -0600)
Add defines for STAT_READ and STAT_WRITE for indexing the partition
stat entries. This clarifies some fs/ code which has hardcoded 1 for
STAT_WRITE and will make it easier to extend the stats with additional
fields.

tj: Refreshed on top of v4.17.

Signed-off-by: Michael Callahan <michaelcallahan@fb.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c
block/partition-generic.c
fs/ext4/super.c
fs/ext4/sysfs.c
fs/f2fs/f2fs.h
fs/f2fs/super.c
include/linux/blk_types.h
include/linux/genhd.h

index f1543a45e73bfa5c5606be2ef4fe67e0d902655e..0711a800d0d4ca15bb40c96313be93edb2a10584 100644 (file)
@@ -1337,14 +1337,14 @@ static int diskstats_show(struct seq_file *seqf, void *v)
                           "%u %lu %lu %lu %u %u %u %u\n",
                           MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
                           disk_name(gp, hd->partno, buf),
-                          part_stat_read(hd, ios[READ]),
-                          part_stat_read(hd, merges[READ]),
-                          part_stat_read(hd, sectors[READ]),
-                          jiffies_to_msecs(part_stat_read(hd, ticks[READ])),
-                          part_stat_read(hd, ios[WRITE]),
-                          part_stat_read(hd, merges[WRITE]),
-                          part_stat_read(hd, sectors[WRITE]),
-                          jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])),
+                          part_stat_read(hd, ios[STAT_READ]),
+                          part_stat_read(hd, merges[STAT_READ]),
+                          part_stat_read(hd, sectors[STAT_READ]),
+                          jiffies_to_msecs(part_stat_read(hd, ticks[STAT_READ])),
+                          part_stat_read(hd, ios[STAT_WRITE]),
+                          part_stat_read(hd, merges[STAT_WRITE]),
+                          part_stat_read(hd, sectors[STAT_WRITE]),
+                          jiffies_to_msecs(part_stat_read(hd, ticks[STAT_WRITE])),
                           inflight[0],
                           jiffies_to_msecs(part_stat_read(hd, io_ticks)),
                           jiffies_to_msecs(part_stat_read(hd, time_in_queue))
index 3dcfd4ec0e11156d468b9eb90c3c190f46755117..0ddb06722162ca82602796e9a8b449e3ddfb7471 100644 (file)
@@ -132,14 +132,14 @@ ssize_t part_stat_show(struct device *dev,
                "%8lu %8lu %8llu %8u "
                "%8u %8u %8u"
                "\n",
-               part_stat_read(p, ios[READ]),
-               part_stat_read(p, merges[READ]),
-               (unsigned long long)part_stat_read(p, sectors[READ]),
-               jiffies_to_msecs(part_stat_read(p, ticks[READ])),
-               part_stat_read(p, ios[WRITE]),
-               part_stat_read(p, merges[WRITE]),
-               (unsigned long long)part_stat_read(p, sectors[WRITE]),
-               jiffies_to_msecs(part_stat_read(p, ticks[WRITE])),
+               part_stat_read(p, ios[STAT_READ]),
+               part_stat_read(p, merges[STAT_READ]),
+               (unsigned long long)part_stat_read(p, sectors[STAT_READ]),
+               jiffies_to_msecs(part_stat_read(p, ticks[STAT_READ])),
+               part_stat_read(p, ios[STAT_WRITE]),
+               part_stat_read(p, merges[STAT_WRITE]),
+               (unsigned long long)part_stat_read(p, sectors[STAT_WRITE]),
+               jiffies_to_msecs(part_stat_read(p, ticks[STAT_WRITE])),
                inflight[0],
                jiffies_to_msecs(part_stat_read(p, io_ticks)),
                jiffies_to_msecs(part_stat_read(p, time_in_queue)));
index ba2396a7bd04b099ed1726a8100d6983954efd36..4b8aef98955238e48233557cb7bbf507931b39f1 100644 (file)
@@ -3514,7 +3514,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
        sbi->s_sb_block = sb_block;
        if (sb->s_bdev->bd_part)
                sbi->s_sectors_written_start =
-                       part_stat_read(sb->s_bdev->bd_part, sectors[1]);
+                       part_stat_read(sb->s_bdev->bd_part, sectors[STAT_WRITE]);
 
        /* Cleanup superblock name */
        strreplace(sb->s_id, '/', '!');
@@ -4824,7 +4824,8 @@ static int ext4_commit_super(struct super_block *sb, int sync)
        if (sb->s_bdev->bd_part)
                es->s_kbytes_written =
                        cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
-                           ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
+                           ((part_stat_read(sb->s_bdev->bd_part,
+                                            sectors[STAT_WRITE]) -
                              EXT4_SB(sb)->s_sectors_written_start) >> 1));
        else
                es->s_kbytes_written =
index f34da0bb8f17445bbfb822a41d387dd0a4ac37dc..2be9ad79001728b9000dbd2b37af238ca3578d5e 100644 (file)
@@ -56,7 +56,8 @@ static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
        if (!sb->s_bdev->bd_part)
                return snprintf(buf, PAGE_SIZE, "0\n");
        return snprintf(buf, PAGE_SIZE, "%lu\n",
-                       (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
+                       (part_stat_read(sb->s_bdev->bd_part,
+                                       sectors[STAT_WRITE]) -
                         sbi->s_sectors_written_start) >> 1);
 }
 
@@ -68,7 +69,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
                return snprintf(buf, PAGE_SIZE, "0\n");
        return snprintf(buf, PAGE_SIZE, "%llu\n",
                        (unsigned long long)(sbi->s_kbytes_written +
-                       ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
+                       ((part_stat_read(sb->s_bdev->bd_part,
+                                        sectors[STAT_WRITE]) -
                          EXT4_SB(sb)->s_sectors_written_start) >> 1)));
 }
 
index 4d8b1de831439ae8b6e4c493a388ef5045224225..6799c3fc44e30d5f2c475d215e5a19d2dde1d2a0 100644 (file)
@@ -1304,7 +1304,7 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
  * and the return value is in kbytes. s is of struct f2fs_sb_info.
  */
 #define BD_PART_WRITTEN(s)                                              \
-(((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) -           \
+(((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) -   \
                (s)->sectors_written_start) >> 1)
 
 static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
index 3995e926ba3a366218d4ddc4ec2bcaccb0e855ab..17bcff789c082a5d185b8b8516d97dcaeda6272e 100644 (file)
@@ -2882,7 +2882,8 @@ try_onemore:
        /* For write statistics */
        if (sb->s_bdev->bd_part)
                sbi->sectors_written_start =
-                       (u64)part_stat_read(sb->s_bdev->bd_part, sectors[1]);
+                       (u64)part_stat_read(sb->s_bdev->bd_part,
+                                           sectors[STAT_WRITE]);
 
        /* Read accumulated write IO statistics if exists */
        seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
index e13449a379a172fccf536997a3ddf7ade389493c..d2b44de56bc1f1e72cc40abcbf68e7639441b951 100644 (file)
@@ -357,6 +357,13 @@ enum req_flag_bits {
 #define REQ_NOMERGE_FLAGS \
        (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
 
+enum stat_group {
+       STAT_READ,
+       STAT_WRITE,
+
+       NR_STAT_GROUPS
+};
+
 #define bio_op(bio) \
        ((bio)->bi_opf & REQ_OP_MASK)
 #define req_op(req) \
index 19f36fa1099509042fcfbed8508c611b5ad04c63..a75445446974a707a08b37cb9e9c8b4dc8425efc 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/slab.h>
 #include <linux/percpu-refcount.h>
 #include <linux/uuid.h>
+#include <linux/blk_types.h>
 
 #ifdef CONFIG_BLOCK
 
@@ -82,10 +83,10 @@ struct partition {
 } __attribute__((packed));
 
 struct disk_stats {
-       unsigned long sectors[2];       /* READs and WRITEs */
-       unsigned long ios[2];
-       unsigned long merges[2];
-       unsigned long ticks[2];
+       unsigned long sectors[NR_STAT_GROUPS];
+       unsigned long ios[NR_STAT_GROUPS];
+       unsigned long merges[NR_STAT_GROUPS];
+       unsigned long ticks[NR_STAT_GROUPS];
        unsigned long io_ticks;
        unsigned long time_in_queue;
 };
@@ -354,8 +355,8 @@ static inline void free_part_stats(struct hd_struct *part)
 #endif /* CONFIG_SMP */
 
 #define part_stat_read_accum(part, field)                              \
-       (part_stat_read(part, field[0]) +                               \
-        part_stat_read(part, field[1]))
+       (part_stat_read(part, field[STAT_READ]) +                       \
+        part_stat_read(part, field[STAT_WRITE]))
 
 #define part_stat_add(cpu, part, field, addnd) do {                    \
        __part_stat_add((cpu), (part), field, addnd);                   \