Skip to content

Commit dbae2c5

Browse files
mcallahanaxboe
authored andcommitted
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>
1 parent 59767fb commit dbae2c5

8 files changed

Lines changed: 40 additions & 28 deletions

File tree

‎block/genhd.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,14 +1337,14 @@ static int diskstats_show(struct seq_file *seqf, void *v)
13371337
"%u %lu %lu %lu %u %u %u %u\n",
13381338
MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
13391339
disk_name(gp, hd->partno, buf),
1340-
part_stat_read(hd, ios[READ]),
1341-
part_stat_read(hd, merges[READ]),
1342-
part_stat_read(hd, sectors[READ]),
1343-
jiffies_to_msecs(part_stat_read(hd, ticks[READ])),
1344-
part_stat_read(hd, ios[WRITE]),
1345-
part_stat_read(hd, merges[WRITE]),
1346-
part_stat_read(hd, sectors[WRITE]),
1347-
jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])),
1340+
part_stat_read(hd, ios[STAT_READ]),
1341+
part_stat_read(hd, merges[STAT_READ]),
1342+
part_stat_read(hd, sectors[STAT_READ]),
1343+
jiffies_to_msecs(part_stat_read(hd, ticks[STAT_READ])),
1344+
part_stat_read(hd, ios[STAT_WRITE]),
1345+
part_stat_read(hd, merges[STAT_WRITE]),
1346+
part_stat_read(hd, sectors[STAT_WRITE]),
1347+
jiffies_to_msecs(part_stat_read(hd, ticks[STAT_WRITE])),
13481348
inflight[0],
13491349
jiffies_to_msecs(part_stat_read(hd, io_ticks)),
13501350
jiffies_to_msecs(part_stat_read(hd, time_in_queue))

‎block/partition-generic.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ ssize_t part_stat_show(struct device *dev,
132132
"%8lu %8lu %8llu %8u "
133133
"%8u %8u %8u"
134134
"\n",
135-
part_stat_read(p, ios[READ]),
136-
part_stat_read(p, merges[READ]),
137-
(unsigned long long)part_stat_read(p, sectors[READ]),
138-
jiffies_to_msecs(part_stat_read(p, ticks[READ])),
139-
part_stat_read(p, ios[WRITE]),
140-
part_stat_read(p, merges[WRITE]),
141-
(unsigned long long)part_stat_read(p, sectors[WRITE]),
142-
jiffies_to_msecs(part_stat_read(p, ticks[WRITE])),
135+
part_stat_read(p, ios[STAT_READ]),
136+
part_stat_read(p, merges[STAT_READ]),
137+
(unsigned long long)part_stat_read(p, sectors[STAT_READ]),
138+
jiffies_to_msecs(part_stat_read(p, ticks[STAT_READ])),
139+
part_stat_read(p, ios[STAT_WRITE]),
140+
part_stat_read(p, merges[STAT_WRITE]),
141+
(unsigned long long)part_stat_read(p, sectors[STAT_WRITE]),
142+
jiffies_to_msecs(part_stat_read(p, ticks[STAT_WRITE])),
143143
inflight[0],
144144
jiffies_to_msecs(part_stat_read(p, io_ticks)),
145145
jiffies_to_msecs(part_stat_read(p, time_in_queue)));

‎fs/ext4/super.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,7 +3514,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
35143514
sbi->s_sb_block = sb_block;
35153515
if (sb->s_bdev->bd_part)
35163516
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]);
35183518

35193519
/* Cleanup superblock name */
35203520
strreplace(sb->s_id, '/', '!');
@@ -4824,7 +4824,8 @@ static int ext4_commit_super(struct super_block *sb, int sync)
48244824
if (sb->s_bdev->bd_part)
48254825
es->s_kbytes_written =
48264826
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]) -
48284829
EXT4_SB(sb)->s_sectors_written_start) >> 1));
48294830
else
48304831
es->s_kbytes_written =

‎fs/ext4/sysfs.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
5656
if (!sb->s_bdev->bd_part)
5757
return snprintf(buf, PAGE_SIZE, "0\n");
5858
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]) -
6061
sbi->s_sectors_written_start) >> 1);
6162
}
6263

@@ -68,7 +69,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
6869
return snprintf(buf, PAGE_SIZE, "0\n");
6970
return snprintf(buf, PAGE_SIZE, "%llu\n",
7071
(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]) -
7274
EXT4_SB(sb)->s_sectors_written_start) >> 1)));
7375
}
7476

‎fs/f2fs/f2fs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
13041304
* and the return value is in kbytes. s is of struct f2fs_sb_info.
13051305
*/
13061306
#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]) - \
13081308
(s)->sectors_written_start) >> 1)
13091309

13101310
static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)

‎fs/f2fs/super.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2882,7 +2882,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
28822882
/* For write statistics */
28832883
if (sb->s_bdev->bd_part)
28842884
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]);
28862887

28872888
/* Read accumulated write IO statistics if exists */
28882889
seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);

‎include/linux/blk_types.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ enum req_flag_bits {
357357
#define REQ_NOMERGE_FLAGS \
358358
(REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
359359

360+
enum stat_group {
361+
STAT_READ,
362+
STAT_WRITE,
363+
364+
NR_STAT_GROUPS
365+
};
366+
360367
#define bio_op(bio) \
361368
((bio)->bi_opf & REQ_OP_MASK)
362369
#define req_op(req) \

‎include/linux/genhd.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/slab.h>
1717
#include <linux/percpu-refcount.h>
1818
#include <linux/uuid.h>
19+
#include <linux/blk_types.h>
1920

2021
#ifdef CONFIG_BLOCK
2122

@@ -82,10 +83,10 @@ struct partition {
8283
} __attribute__((packed));
8384

8485
struct disk_stats {
85-
unsigned long sectors[2]; /* READs and WRITEs */
86-
unsigned long ios[2];
87-
unsigned long merges[2];
88-
unsigned long ticks[2];
86+
unsigned long sectors[NR_STAT_GROUPS];
87+
unsigned long ios[NR_STAT_GROUPS];
88+
unsigned long merges[NR_STAT_GROUPS];
89+
unsigned long ticks[NR_STAT_GROUPS];
8990
unsigned long io_ticks;
9091
unsigned long time_in_queue;
9192
};
@@ -354,8 +355,8 @@ static inline void free_part_stats(struct hd_struct *part)
354355
#endif /* CONFIG_SMP */
355356

356357
#define part_stat_read_accum(part, field) \
357-
(part_stat_read(part, field[0]) + \
358-
part_stat_read(part, field[1]))
358+
(part_stat_read(part, field[STAT_READ]) + \
359+
part_stat_read(part, field[STAT_WRITE]))
359360

360361
#define part_stat_add(cpu, part, field, addnd) do { \
361362
__part_stat_add((cpu), (part), field, addnd); \

0 commit comments

Comments
 (0)