f2fs: introduce sysfs atomic write statistics
PATCH 1/1 f2fs: introduce sysfs atomic write statistics
From: Daeho Jeong <[email protected]>
introduce the below 4 new sysfs node for atomic write statistics.
- current_atomic_write: the total current atomic write block count, which is not committed yet.
- peak_atomic_write: the peak value of total current atomic write block count after boot.
- committed_atomic_block: the accumulated total committed atomic write block count after boot.
- revoked_atomic_block: the accumulated total revoked atomic write block count after boot.
Signed-off-by Daeho Jeong <[email protected]>
--- Documentation/ABI/testing/sysfs-fs-f2fs | 25 ++++++++++++++ fs/f2fs/data.c | 7 ++-- fs/f2fs/f2fs.h | 30 ++++++++++++++++ fs/f2fs/file.c | 1 + fs/f2fs/segment.c | 6 ++++ fs/f2fs/super.c | 1 + fs/f2fs/sysfs.c | 46 +++++++++++++++++++++++++ 7 files changed, 113 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +25 -0
@@ -586,3 +586,28 @@ Date: June 2022 Contact: "Jaegeuk Kim" <[email protected]> Description: Shows the number of unusable blocks in a section which was defined by the zone capacity reported by underlying zoned device. + +What: /sys/fs/f2fs/<disk>/current_atomic_write +Date: July 2022 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the total current atomic write block count, which is not committed yet. + This is a read-only entry. + +What: /sys/fs/f2fs/<disk>/peak_atomic_write +Date: July 2022 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the peak value of total current atomic write block count after boot. + If you write "0" here, you can initialize to "0". + +What: /sys/fs/f2fs/<disk>/committed_atomic_block +Date: July 2022 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the accumulated total committed atomic write block count after boot. + If you write "0" here, you can initialize to "0". + +What: /sys/fs/f2fs/<disk>/revoked_atomic_block +Date: July 2022 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the accumulated total revoked atomic write block count after boot. + If you write "0" here, you can initialize to "0". +
fs/f2fs/data.c +4 -3
@@ -3423,12 +3423,11 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,struct inode *cow_inode =F2FS_I (inode)->cow_inode;pgoff_t index = page->index;int err =0 ; -block_t ori_blk_addr; +block_t ori_blk_addr =NULL_ADDR ;/* If pos is beyond the end of file, reserve a new block in COW inode */ if ((pos &PAGE_MASK ) >=i_size_read (inode)) -return __reserve_data_block (cow_inode, index, blk_addr, - node_changed); + goto reserve_block;/* Look for the block in COW inode first */ err =__find_data_block (cow_inode, index, blk_addr);
@@ -3442,10 +3441,12 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,if (err)return err; +reserve_block:/* Finally, we should reserve a new block in COW inode for the update */ err =__reserve_data_block (cow_inode, index, blk_addr, node_changed);if (err)return err; +inc_atomic_write_cnt (inode);if (ori_blk_addr !=NULL_ADDR ) *blk_addr = ori_blk_addr;
fs/f2fs/f2fs.h +30 -0
@@ -813,6 +813,8 @@ struct f2fs_inode_info {unsigned char i_compress_level;/* compress level (lz4hc,zstd) */ unsigned short i_compress_flag;/* compress flag */ unsigned int i_cluster_size;/* cluster size */ + +unsigned int atomic_write_cnt; }; static inline void get_extent_info(struct extent_info *ext,
@@ -1813,6 +1815,12 @@ struct f2fs_sb_info {int max_fragment_chunk;/* max chunk size for block fragmentation mode */ int max_fragment_hole;/* max hole size for block fragmentation mode */ +/* For atomic write statistics */ +atomic64_t current_atomic_write; +s64 peak_atomic_write; +u64 committed_atomic_block; +u64 revoked_atomic_block; +#ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab;/* page array entry */ unsigned int page_array_slab_size;/* default page array slab size */
@@ -2427,6 +2435,28 @@ static inline void inode_dec_dirty_pages(struct inode *inode)dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_QDATA ); } +static inline void inc_atomic_write_cnt (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +struct f2fs_inode_info *fi =F2FS_I (inode); +u64 current_write; + + fi->atomic_write_cnt++; +atomic64_inc (&sbi->current_atomic_write); + current_write =atomic64_read (&sbi->current_atomic_write); +if (current_write > sbi->peak_atomic_write) + sbi->peak_atomic_write = current_write; +} + +static inline void release_atomic_write_cnt (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +struct f2fs_inode_info *fi =F2FS_I (inode); + +atomic64_sub (fi->atomic_write_cnt, &sbi->current_atomic_write); + fi->atomic_write_cnt =0 ; +} +static inline s64 get_pages (struct f2fs_sb_info *sbi,int count_type) {return atomic_read (&sbi->nr_pages[count_type]);
fs/f2fs/file.c +1 -0
@@ -2075,6 +2075,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)f2fs_update_time (sbi,REQ_TIME ); fi->atomic_write_task = current;stat_update_max_atomic_write (inode); + fi->atomic_write_cnt =0 ; out:inode_unlock (inode);mnt_drop_write_file (filp);
fs/f2fs/segment.c +6 -0
@@ -196,6 +196,7 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean)clear_inode_flag (fi->cow_inode,FI_ATOMIC_FILE );iput (fi->cow_inode); fi->cow_inode =NULL ; +release_atomic_write_cnt (inode);clear_inode_flag (inode,FI_ATOMIC_FILE );spin_lock (&sbi->inode_lock[ATOMIC_FILE ]);
@@ -335,6 +336,11 @@ static int __f2fs_commit_atomic_write(struct inode *inode) } out: +if (ret) + sbi->revoked_atomic_block += fi->atomic_write_cnt; +else + sbi->committed_atomic_block += fi->atomic_write_cnt; +__complete_revoke_list (inode, &revoke_list, ret ? true : false);return ret;
fs/f2fs/super.c +1 -0
@@ -3615,6 +3615,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->max_fragment_chunk =DEF_FRAGMENT_SIZE ; sbi->max_fragment_hole =DEF_FRAGMENT_SIZE ;spin_lock_init (&sbi->gc_urgent_high_lock); +atomic64_set (&sbi->current_atomic_write,0 ); sbi->dir_level =DEF_DIR_LEVEL ; sbi->interval_time[CP_TIME ] =DEF_CP_INTERVAL ;
fs/f2fs/sysfs.c +46 -0
70 lines not on this page · raw message
Signature · 1 line
2.37.0.170.g444d1eabd0-goog