Skip to content

Commit 8b83ac8

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: support read iostat
Adds to support accounting read IOs from userspace/kernel. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent df42339 commit 8b83ac8

File tree

8 files changed

+118
-31
lines changed

8 files changed

+118
-31
lines changed

fs/f2fs/checkpoint.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
8686
return ERR_PTR(err);
8787
}
8888

89+
f2fs_update_iostat(sbi, FS_META_READ_IO, F2FS_BLKSIZE);
90+
8991
lock_page(page);
9092
if (unlikely(page->mapping != mapping)) {
9193
f2fs_put_page(page, 1);
@@ -266,6 +268,9 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
266268
fio.page = page;
267269
err = f2fs_submit_page_bio(&fio);
268270
f2fs_put_page(page, err ? 1 : 0);
271+
272+
if (!err)
273+
f2fs_update_iostat(sbi, FS_META_READ_IO, F2FS_BLKSIZE);
269274
}
270275
out:
271276
blk_finish_plug(&plug);

fs/f2fs/data.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page,
10331033
}
10341034
ClearPageError(page);
10351035
inc_page_count(sbi, F2FS_RD_DATA);
1036+
f2fs_update_iostat(sbi, FS_DATA_READ_IO, F2FS_BLKSIZE);
10361037
__submit_bio(sbi, bio, DATA);
10371038
return 0;
10381039
}
@@ -2038,6 +2039,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
20382039
goto submit_and_realloc;
20392040

20402041
inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
2042+
f2fs_update_iostat(F2FS_I_SB(inode), FS_DATA_READ_IO, F2FS_BLKSIZE);
20412043
ClearPageError(page);
20422044
*last_block_in_bio = block_nr;
20432045
goto out;
@@ -2173,6 +2175,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
21732175
goto submit_and_realloc;
21742176

21752177
inc_page_count(sbi, F2FS_RD_DATA);
2178+
f2fs_update_iostat(sbi, FS_DATA_READ_IO, F2FS_BLKSIZE);
21762179
ClearPageError(page);
21772180
*last_block_in_bio = blkaddr;
21782181
}
@@ -3526,6 +3529,9 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
35263529
} else if (err < 0) {
35273530
f2fs_write_failed(mapping, offset + count);
35283531
}
3532+
} else {
3533+
if (err > 0)
3534+
f2fs_update_iostat(sbi, APP_DIRECT_READ_IO, err);
35293535
}
35303536

35313537
out:

fs/f2fs/f2fs.h

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,9 @@ enum cp_reason_type {
10881088
};
10891089

10901090
enum iostat_type {
1091-
APP_DIRECT_IO, /* app direct IOs */
1092-
APP_BUFFERED_IO, /* app buffered IOs */
1091+
/* WRITE IO */
1092+
APP_DIRECT_IO, /* app direct write IOs */
1093+
APP_BUFFERED_IO, /* app buffered write IOs */
10931094
APP_WRITE_IO, /* app write IOs */
10941095
APP_MAPPED_IO, /* app mapped IOs */
10951096
FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */
@@ -1100,6 +1101,17 @@ enum iostat_type {
11001101
FS_CP_DATA_IO, /* data IOs from checkpoint */
11011102
FS_CP_NODE_IO, /* node IOs from checkpoint */
11021103
FS_CP_META_IO, /* meta IOs from checkpoint */
1104+
1105+
/* READ IO */
1106+
APP_DIRECT_READ_IO, /* app direct read IOs */
1107+
APP_BUFFERED_READ_IO, /* app buffered read IOs */
1108+
APP_READ_IO, /* app read IOs */
1109+
APP_MAPPED_READ_IO, /* app mapped read IOs */
1110+
FS_DATA_READ_IO, /* data read IOs */
1111+
FS_NODE_READ_IO, /* node read IOs */
1112+
FS_META_READ_IO, /* meta read IOs */
1113+
1114+
/* other */
11031115
FS_DISCARD, /* discard */
11041116
NR_IO_TYPE,
11051117
};
@@ -1504,8 +1516,8 @@ struct f2fs_sb_info {
15041516

15051517
/* For app/fs IO statistics */
15061518
spinlock_t iostat_lock;
1507-
unsigned long long write_iostat[NR_IO_TYPE];
1508-
unsigned long long prev_write_iostat[NR_IO_TYPE];
1519+
unsigned long long rw_iostat[NR_IO_TYPE];
1520+
unsigned long long prev_rw_iostat[NR_IO_TYPE];
15091521
bool iostat_enable;
15101522
unsigned long iostat_next_period;
15111523
unsigned int iostat_period_ms;
@@ -3013,8 +3025,8 @@ static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
30133025

30143026
spin_lock(&sbi->iostat_lock);
30153027
for (i = 0; i < NR_IO_TYPE; i++) {
3016-
sbi->write_iostat[i] = 0;
3017-
sbi->prev_write_iostat[i] = 0;
3028+
sbi->rw_iostat[i] = 0;
3029+
sbi->prev_rw_iostat[i] = 0;
30183030
}
30193031
spin_unlock(&sbi->iostat_lock);
30203032
}
@@ -3027,12 +3039,17 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
30273039
if (!sbi->iostat_enable)
30283040
return;
30293041
spin_lock(&sbi->iostat_lock);
3030-
sbi->write_iostat[type] += io_bytes;
3042+
sbi->rw_iostat[type] += io_bytes;
30313043

30323044
if (type == APP_WRITE_IO || type == APP_DIRECT_IO)
3033-
sbi->write_iostat[APP_BUFFERED_IO] =
3034-
sbi->write_iostat[APP_WRITE_IO] -
3035-
sbi->write_iostat[APP_DIRECT_IO];
3045+
sbi->rw_iostat[APP_BUFFERED_IO] =
3046+
sbi->rw_iostat[APP_WRITE_IO] -
3047+
sbi->rw_iostat[APP_DIRECT_IO];
3048+
3049+
if (type == APP_READ_IO || type == APP_DIRECT_READ_IO)
3050+
sbi->rw_iostat[APP_BUFFERED_READ_IO] =
3051+
sbi->rw_iostat[APP_READ_IO] -
3052+
sbi->rw_iostat[APP_DIRECT_READ_IO];
30363053
spin_unlock(&sbi->iostat_lock);
30373054

30383055
f2fs_record_iostat(sbi);

fs/f2fs/file.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf)
4040
ret = filemap_fault(vmf);
4141
up_read(&F2FS_I(inode)->i_mmap_sem);
4242

43+
if (!ret)
44+
f2fs_update_iostat(F2FS_I_SB(inode), APP_MAPPED_READ_IO,
45+
F2FS_BLKSIZE);
46+
4347
trace_f2fs_filemap_fault(inode, vmf->pgoff, (unsigned long)ret);
4448

4549
return ret;
@@ -3510,11 +3514,17 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
35103514
{
35113515
struct file *file = iocb->ki_filp;
35123516
struct inode *inode = file_inode(file);
3517+
int ret;
35133518

35143519
if (!f2fs_is_compress_backend_ready(inode))
35153520
return -EOPNOTSUPP;
35163521

3517-
return generic_file_read_iter(iocb, iter);
3522+
ret = generic_file_read_iter(iocb, iter);
3523+
3524+
if (ret > 0)
3525+
f2fs_update_iostat(F2FS_I_SB(inode), APP_READ_IO, ret);
3526+
3527+
return ret;
35183528
}
35193529

35203530
static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)

fs/f2fs/gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,9 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
737737
goto put_encrypted_page;
738738
f2fs_put_page(fio.encrypted_page, 0);
739739
f2fs_put_page(page, 1);
740+
741+
f2fs_update_iostat(sbi, FS_DATA_READ_IO, F2FS_BLKSIZE);
742+
740743
return 0;
741744
put_encrypted_page:
742745
f2fs_put_page(fio.encrypted_page, 1);
@@ -840,6 +843,9 @@ static int move_data_block(struct inode *inode, block_t bidx,
840843
f2fs_put_page(mpage, 1);
841844
goto up_out;
842845
}
846+
847+
f2fs_update_iostat(fio.sbi, FS_DATA_READ_IO, F2FS_BLKSIZE);
848+
843849
lock_page(mpage);
844850
if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) ||
845851
!PageUptodate(mpage))) {

fs/f2fs/node.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,13 @@ static int read_node_page(struct page *page, int op_flags)
13001300
}
13011301

13021302
fio.new_blkaddr = fio.old_blkaddr = ni.blk_addr;
1303-
return f2fs_submit_page_bio(&fio);
1303+
1304+
err = f2fs_submit_page_bio(&fio);
1305+
1306+
if (!err)
1307+
f2fs_update_iostat(sbi, FS_NODE_READ_IO, F2FS_BLKSIZE);
1308+
1309+
return err;
13041310
}
13051311

13061312
/*

fs/f2fs/sysfs.c

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,9 @@ void f2fs_record_iostat(struct f2fs_sb_info *sbi)
781781
msecs_to_jiffies(sbi->iostat_period_ms);
782782

783783
for (i = 0; i < NR_IO_TYPE; i++) {
784-
iostat_diff[i] = sbi->write_iostat[i] -
785-
sbi->prev_write_iostat[i];
786-
sbi->prev_write_iostat[i] = sbi->write_iostat[i];
784+
iostat_diff[i] = sbi->rw_iostat[i] -
785+
sbi->prev_rw_iostat[i];
786+
sbi->prev_rw_iostat[i] = sbi->rw_iostat[i];
787787
}
788788
spin_unlock(&sbi->iostat_lock);
789789

@@ -802,33 +802,51 @@ static int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
802802

803803
seq_printf(seq, "time: %-16llu\n", now);
804804

805-
/* print app IOs */
805+
/* print app write IOs */
806806
seq_printf(seq, "app buffered: %-16llu\n",
807-
sbi->write_iostat[APP_BUFFERED_IO]);
807+
sbi->rw_iostat[APP_BUFFERED_IO]);
808808
seq_printf(seq, "app direct: %-16llu\n",
809-
sbi->write_iostat[APP_DIRECT_IO]);
809+
sbi->rw_iostat[APP_DIRECT_IO]);
810810
seq_printf(seq, "app mapped: %-16llu\n",
811-
sbi->write_iostat[APP_MAPPED_IO]);
811+
sbi->rw_iostat[APP_MAPPED_IO]);
812812

813-
/* print fs IOs */
813+
/* print fs write IOs */
814814
seq_printf(seq, "fs data: %-16llu\n",
815-
sbi->write_iostat[FS_DATA_IO]);
815+
sbi->rw_iostat[FS_DATA_IO]);
816816
seq_printf(seq, "fs node: %-16llu\n",
817-
sbi->write_iostat[FS_NODE_IO]);
817+
sbi->rw_iostat[FS_NODE_IO]);
818818
seq_printf(seq, "fs meta: %-16llu\n",
819-
sbi->write_iostat[FS_META_IO]);
819+
sbi->rw_iostat[FS_META_IO]);
820820
seq_printf(seq, "fs gc data: %-16llu\n",
821-
sbi->write_iostat[FS_GC_DATA_IO]);
821+
sbi->rw_iostat[FS_GC_DATA_IO]);
822822
seq_printf(seq, "fs gc node: %-16llu\n",
823-
sbi->write_iostat[FS_GC_NODE_IO]);
823+
sbi->rw_iostat[FS_GC_NODE_IO]);
824824
seq_printf(seq, "fs cp data: %-16llu\n",
825-
sbi->write_iostat[FS_CP_DATA_IO]);
825+
sbi->rw_iostat[FS_CP_DATA_IO]);
826826
seq_printf(seq, "fs cp node: %-16llu\n",
827-
sbi->write_iostat[FS_CP_NODE_IO]);
827+
sbi->rw_iostat[FS_CP_NODE_IO]);
828828
seq_printf(seq, "fs cp meta: %-16llu\n",
829-
sbi->write_iostat[FS_CP_META_IO]);
829+
sbi->rw_iostat[FS_CP_META_IO]);
830+
831+
/* print app read IOs */
832+
seq_printf(seq, "app buffered: %-16llu\n",
833+
sbi->rw_iostat[APP_BUFFERED_READ_IO]);
834+
seq_printf(seq, "app direct: %-16llu\n",
835+
sbi->rw_iostat[APP_DIRECT_READ_IO]);
836+
seq_printf(seq, "app mapped: %-16llu\n",
837+
sbi->rw_iostat[APP_MAPPED_READ_IO]);
838+
839+
/* print fs read IOs */
840+
seq_printf(seq, "fs data: %-16llu\n",
841+
sbi->rw_iostat[FS_DATA_READ_IO]);
842+
seq_printf(seq, "fs node: %-16llu\n",
843+
sbi->rw_iostat[FS_NODE_READ_IO]);
844+
seq_printf(seq, "fs meta: %-16llu\n",
845+
sbi->rw_iostat[FS_META_READ_IO]);
846+
847+
/* print other IOs */
830848
seq_printf(seq, "fs discard: %-16llu\n",
831-
sbi->write_iostat[FS_DISCARD]);
849+
sbi->rw_iostat[FS_DISCARD]);
832850

833851
return 0;
834852
}

include/trace/events/f2fs.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,13 @@ TRACE_EVENT(f2fs_iostat,
18321832
__field(unsigned long long, fs_cp_dio)
18331833
__field(unsigned long long, fs_cp_nio)
18341834
__field(unsigned long long, fs_cp_mio)
1835+
__field(unsigned long long, app_drio)
1836+
__field(unsigned long long, app_brio)
1837+
__field(unsigned long long, app_rio)
1838+
__field(unsigned long long, app_mrio)
1839+
__field(unsigned long long, fs_drio)
1840+
__field(unsigned long long, fs_nrio)
1841+
__field(unsigned long long, fs_mrio)
18351842
__field(unsigned long long, fs_discard)
18361843
),
18371844

@@ -1849,19 +1856,31 @@ TRACE_EVENT(f2fs_iostat,
18491856
__entry->fs_cp_dio = iostat[FS_CP_DATA_IO];
18501857
__entry->fs_cp_nio = iostat[FS_CP_NODE_IO];
18511858
__entry->fs_cp_mio = iostat[FS_CP_META_IO];
1859+
__entry->app_drio = iostat[APP_DIRECT_READ_IO];
1860+
__entry->app_brio = iostat[APP_BUFFERED_READ_IO];
1861+
__entry->app_rio = iostat[APP_READ_IO];
1862+
__entry->app_mrio = iostat[APP_MAPPED_READ_IO];
1863+
__entry->fs_drio = iostat[FS_DATA_READ_IO];
1864+
__entry->fs_nrio = iostat[FS_NODE_READ_IO];
1865+
__entry->fs_mrio = iostat[FS_META_READ_IO];
18521866
__entry->fs_discard = iostat[FS_DISCARD];
18531867
),
18541868

18551869
TP_printk("dev = (%d,%d), "
18561870
"app [write=%llu (direct=%llu, buffered=%llu), mapped=%llu], "
18571871
"fs [data=%llu, node=%llu, meta=%llu, discard=%llu], "
18581872
"gc [data=%llu, node=%llu], "
1859-
"cp [data=%llu, node=%llu, meta=%llu]",
1873+
"cp [data=%llu, node=%llu, meta=%llu], "
1874+
"app [read=%llu (direct=%llu, buffered=%llu), mapped=%llu], "
1875+
"fs [data=%llu, node=%llu, meta=%llu]",
18601876
show_dev(__entry->dev), __entry->app_wio, __entry->app_dio,
18611877
__entry->app_bio, __entry->app_mio, __entry->fs_dio,
18621878
__entry->fs_nio, __entry->fs_mio, __entry->fs_discard,
18631879
__entry->fs_gc_dio, __entry->fs_gc_nio, __entry->fs_cp_dio,
1864-
__entry->fs_cp_nio, __entry->fs_cp_mio)
1880+
__entry->fs_cp_nio, __entry->fs_cp_mio,
1881+
__entry->app_rio, __entry->app_drio, __entry->app_brio,
1882+
__entry->app_mrio, __entry->fs_drio, __entry->fs_nrio,
1883+
__entry->fs_mrio)
18651884
);
18661885

18671886
#endif /* _TRACE_F2FS_H */

0 commit comments

Comments
 (0)