diff options
author | Michael Callahan <michaelcallahan@fb.com> | 2018-07-18 07:47:38 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-07-18 10:44:18 -0400 |
commit | dbae2c551377b6533a00c11fc7ede370100ab404 (patch) | |
tree | bbbfb46c0d4c3ff3b9250f70453b259c58e89539 | |
parent | 59767fbd49d794b4499d30b314df6c0d4aca584b (diff) |
block: Define and use STAT_READ and STAT_WRITE
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>
-rw-r--r-- | block/genhd.c | 16 | ||||
-rw-r--r-- | block/partition-generic.c | 16 | ||||
-rw-r--r-- | fs/ext4/super.c | 5 | ||||
-rw-r--r-- | fs/ext4/sysfs.c | 6 | ||||
-rw-r--r-- | fs/f2fs/f2fs.h | 2 | ||||
-rw-r--r-- | fs/f2fs/super.c | 3 | ||||
-rw-r--r-- | include/linux/blk_types.h | 7 | ||||
-rw-r--r-- | include/linux/genhd.h | 13 |
8 files changed, 40 insertions, 28 deletions
diff --git a/block/genhd.c b/block/genhd.c index f1543a45e73b..0711a800d0d4 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -1337,14 +1337,14 @@ static int diskstats_show(struct seq_file *seqf, void *v) | |||
1337 | "%u %lu %lu %lu %u %u %u %u\n", | 1337 | "%u %lu %lu %lu %u %u %u %u\n", |
1338 | MAJOR(part_devt(hd)), MINOR(part_devt(hd)), | 1338 | MAJOR(part_devt(hd)), MINOR(part_devt(hd)), |
1339 | disk_name(gp, hd->partno, buf), | 1339 | disk_name(gp, hd->partno, buf), |
1340 | part_stat_read(hd, ios[READ]), | 1340 | part_stat_read(hd, ios[STAT_READ]), |
1341 | part_stat_read(hd, merges[READ]), | 1341 | part_stat_read(hd, merges[STAT_READ]), |
1342 | part_stat_read(hd, sectors[READ]), | 1342 | part_stat_read(hd, sectors[STAT_READ]), |
1343 | jiffies_to_msecs(part_stat_read(hd, ticks[READ])), | 1343 | jiffies_to_msecs(part_stat_read(hd, ticks[STAT_READ])), |
1344 | part_stat_read(hd, ios[WRITE]), | 1344 | part_stat_read(hd, ios[STAT_WRITE]), |
1345 | part_stat_read(hd, merges[WRITE]), | 1345 | part_stat_read(hd, merges[STAT_WRITE]), |
1346 | part_stat_read(hd, sectors[WRITE]), | 1346 | part_stat_read(hd, sectors[STAT_WRITE]), |
1347 | jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])), | 1347 | jiffies_to_msecs(part_stat_read(hd, ticks[STAT_WRITE])), |
1348 | inflight[0], | 1348 | inflight[0], |
1349 | jiffies_to_msecs(part_stat_read(hd, io_ticks)), | 1349 | jiffies_to_msecs(part_stat_read(hd, io_ticks)), |
1350 | jiffies_to_msecs(part_stat_read(hd, time_in_queue)) | 1350 | jiffies_to_msecs(part_stat_read(hd, time_in_queue)) |
diff --git a/block/partition-generic.c b/block/partition-generic.c index 3dcfd4ec0e11..0ddb06722162 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c | |||
@@ -132,14 +132,14 @@ ssize_t part_stat_show(struct device *dev, | |||
132 | "%8lu %8lu %8llu %8u " | 132 | "%8lu %8lu %8llu %8u " |
133 | "%8u %8u %8u" | 133 | "%8u %8u %8u" |
134 | "\n", | 134 | "\n", |
135 | part_stat_read(p, ios[READ]), | 135 | part_stat_read(p, ios[STAT_READ]), |
136 | part_stat_read(p, merges[READ]), | 136 | part_stat_read(p, merges[STAT_READ]), |
137 | (unsigned long long)part_stat_read(p, sectors[READ]), | 137 | (unsigned long long)part_stat_read(p, sectors[STAT_READ]), |
138 | jiffies_to_msecs(part_stat_read(p, ticks[READ])), | 138 | jiffies_to_msecs(part_stat_read(p, ticks[STAT_READ])), |
139 | part_stat_read(p, ios[WRITE]), | 139 | part_stat_read(p, ios[STAT_WRITE]), |
140 | part_stat_read(p, merges[WRITE]), | 140 | part_stat_read(p, merges[STAT_WRITE]), |
141 | (unsigned long long)part_stat_read(p, sectors[WRITE]), | 141 | (unsigned long long)part_stat_read(p, sectors[STAT_WRITE]), |
142 | jiffies_to_msecs(part_stat_read(p, ticks[WRITE])), | 142 | jiffies_to_msecs(part_stat_read(p, ticks[STAT_WRITE])), |
143 | inflight[0], | 143 | inflight[0], |
144 | jiffies_to_msecs(part_stat_read(p, io_ticks)), | 144 | jiffies_to_msecs(part_stat_read(p, io_ticks)), |
145 | jiffies_to_msecs(part_stat_read(p, time_in_queue))); | 145 | jiffies_to_msecs(part_stat_read(p, time_in_queue))); |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index ba2396a7bd04..4b8aef989552 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -3514,7 +3514,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3514 | sbi->s_sb_block = sb_block; | 3514 | sbi->s_sb_block = sb_block; |
3515 | if (sb->s_bdev->bd_part) | 3515 | if (sb->s_bdev->bd_part) |
3516 | sbi->s_sectors_written_start = | 3516 | sbi->s_sectors_written_start = |
3517 | part_stat_read(sb->s_bdev->bd_part, sectors[1]); | 3517 | part_stat_read(sb->s_bdev->bd_part, sectors[STAT_WRITE]); |
3518 | 3518 | ||
3519 | /* Cleanup superblock name */ | 3519 | /* Cleanup superblock name */ |
3520 | strreplace(sb->s_id, '/', '!'); | 3520 | strreplace(sb->s_id, '/', '!'); |
@@ -4824,7 +4824,8 @@ static int ext4_commit_super(struct super_block *sb, int sync) | |||
4824 | if (sb->s_bdev->bd_part) | 4824 | if (sb->s_bdev->bd_part) |
4825 | es->s_kbytes_written = | 4825 | es->s_kbytes_written = |
4826 | cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + | 4826 | cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + |
4827 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 4827 | ((part_stat_read(sb->s_bdev->bd_part, |
4828 | sectors[STAT_WRITE]) - | ||
4828 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); | 4829 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); |
4829 | else | 4830 | else |
4830 | es->s_kbytes_written = | 4831 | es->s_kbytes_written = |
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index f34da0bb8f17..2be9ad790017 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c | |||
@@ -56,7 +56,8 @@ static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) | |||
56 | if (!sb->s_bdev->bd_part) | 56 | if (!sb->s_bdev->bd_part) |
57 | return snprintf(buf, PAGE_SIZE, "0\n"); | 57 | return snprintf(buf, PAGE_SIZE, "0\n"); |
58 | return snprintf(buf, PAGE_SIZE, "%lu\n", | 58 | return snprintf(buf, PAGE_SIZE, "%lu\n", |
59 | (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 59 | (part_stat_read(sb->s_bdev->bd_part, |
60 | sectors[STAT_WRITE]) - | ||
60 | sbi->s_sectors_written_start) >> 1); | 61 | sbi->s_sectors_written_start) >> 1); |
61 | } | 62 | } |
62 | 63 | ||
@@ -68,7 +69,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) | |||
68 | return snprintf(buf, PAGE_SIZE, "0\n"); | 69 | return snprintf(buf, PAGE_SIZE, "0\n"); |
69 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 70 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
70 | (unsigned long long)(sbi->s_kbytes_written + | 71 | (unsigned long long)(sbi->s_kbytes_written + |
71 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 72 | ((part_stat_read(sb->s_bdev->bd_part, |
73 | sectors[STAT_WRITE]) - | ||
72 | EXT4_SB(sb)->s_sectors_written_start) >> 1))); | 74 | EXT4_SB(sb)->s_sectors_written_start) >> 1))); |
73 | } | 75 | } |
74 | 76 | ||
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 4d8b1de83143..6799c3fc44e3 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -1304,7 +1304,7 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) | |||
1304 | * and the return value is in kbytes. s is of struct f2fs_sb_info. | 1304 | * and the return value is in kbytes. s is of struct f2fs_sb_info. |
1305 | */ | 1305 | */ |
1306 | #define BD_PART_WRITTEN(s) \ | 1306 | #define BD_PART_WRITTEN(s) \ |
1307 | (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ | 1307 | (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ |
1308 | (s)->sectors_written_start) >> 1) | 1308 | (s)->sectors_written_start) >> 1) |
1309 | 1309 | ||
1310 | static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) | 1310 | static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 3995e926ba3a..17bcff789c08 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -2882,7 +2882,8 @@ try_onemore: | |||
2882 | /* For write statistics */ | 2882 | /* For write statistics */ |
2883 | if (sb->s_bdev->bd_part) | 2883 | if (sb->s_bdev->bd_part) |
2884 | sbi->sectors_written_start = | 2884 | sbi->sectors_written_start = |
2885 | (u64)part_stat_read(sb->s_bdev->bd_part, sectors[1]); | 2885 | (u64)part_stat_read(sb->s_bdev->bd_part, |
2886 | sectors[STAT_WRITE]); | ||
2886 | 2887 | ||
2887 | /* Read accumulated write IO statistics if exists */ | 2888 | /* Read accumulated write IO statistics if exists */ |
2888 | seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); | 2889 | seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); |
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index e13449a379a1..d2b44de56bc1 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h | |||
@@ -357,6 +357,13 @@ enum req_flag_bits { | |||
357 | #define REQ_NOMERGE_FLAGS \ | 357 | #define REQ_NOMERGE_FLAGS \ |
358 | (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA) | 358 | (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA) |
359 | 359 | ||
360 | enum stat_group { | ||
361 | STAT_READ, | ||
362 | STAT_WRITE, | ||
363 | |||
364 | NR_STAT_GROUPS | ||
365 | }; | ||
366 | |||
360 | #define bio_op(bio) \ | 367 | #define bio_op(bio) \ |
361 | ((bio)->bi_opf & REQ_OP_MASK) | 368 | ((bio)->bi_opf & REQ_OP_MASK) |
362 | #define req_op(req) \ | 369 | #define req_op(req) \ |
diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 19f36fa10995..a75445446974 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/percpu-refcount.h> | 17 | #include <linux/percpu-refcount.h> |
18 | #include <linux/uuid.h> | 18 | #include <linux/uuid.h> |
19 | #include <linux/blk_types.h> | ||
19 | 20 | ||
20 | #ifdef CONFIG_BLOCK | 21 | #ifdef CONFIG_BLOCK |
21 | 22 | ||
@@ -82,10 +83,10 @@ struct partition { | |||
82 | } __attribute__((packed)); | 83 | } __attribute__((packed)); |
83 | 84 | ||
84 | struct disk_stats { | 85 | struct disk_stats { |
85 | unsigned long sectors[2]; /* READs and WRITEs */ | 86 | unsigned long sectors[NR_STAT_GROUPS]; |
86 | unsigned long ios[2]; | 87 | unsigned long ios[NR_STAT_GROUPS]; |
87 | unsigned long merges[2]; | 88 | unsigned long merges[NR_STAT_GROUPS]; |
88 | unsigned long ticks[2]; | 89 | unsigned long ticks[NR_STAT_GROUPS]; |
89 | unsigned long io_ticks; | 90 | unsigned long io_ticks; |
90 | unsigned long time_in_queue; | 91 | unsigned long time_in_queue; |
91 | }; | 92 | }; |
@@ -354,8 +355,8 @@ static inline void free_part_stats(struct hd_struct *part) | |||
354 | #endif /* CONFIG_SMP */ | 355 | #endif /* CONFIG_SMP */ |
355 | 356 | ||
356 | #define part_stat_read_accum(part, field) \ | 357 | #define part_stat_read_accum(part, field) \ |
357 | (part_stat_read(part, field[0]) + \ | 358 | (part_stat_read(part, field[STAT_READ]) + \ |
358 | part_stat_read(part, field[1])) | 359 | part_stat_read(part, field[STAT_WRITE])) |
359 | 360 | ||
360 | #define part_stat_add(cpu, part, field, addnd) do { \ | 361 | #define part_stat_add(cpu, part, field, addnd) do { \ |
361 | __part_stat_add((cpu), (part), field, addnd); \ | 362 | __part_stat_add((cpu), (part), field, addnd); \ |