Commit f8e2f32b authored by Daeho Jeong's avatar Daeho Jeong Committed by Jaegeuk Kim

f2fs: introduce sysfs atomic write statistics

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: default avatarDaeho Jeong <daehojeong@google.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 1adaa71e
...@@ -586,3 +586,27 @@ Date: June 2022 ...@@ -586,3 +586,27 @@ Date: June 2022
Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
Description: Shows the number of unusable blocks in a section which was defined by Description: Shows the number of unusable blocks in a section which was defined by
the zone capacity reported by underlying zoned device. the zone capacity reported by underlying zoned device.
What: /sys/fs/f2fs/<disk>/current_atomic_write
Date: July 2022
Contact: "Daeho Jeong" <daehojeong@google.com>
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" <daehojeong@google.com>
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" <daehojeong@google.com>
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" <daehojeong@google.com>
Description: Show the accumulated total revoked atomic write block count after boot.
If you write "0" here, you can initialize to "0".
...@@ -3406,12 +3406,11 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi, ...@@ -3406,12 +3406,11 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
struct inode *cow_inode = F2FS_I(inode)->cow_inode; struct inode *cow_inode = F2FS_I(inode)->cow_inode;
pgoff_t index = page->index; pgoff_t index = page->index;
int err = 0; 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 is beyond the end of file, reserve a new block in COW inode */
if ((pos & PAGE_MASK) >= i_size_read(inode)) if ((pos & PAGE_MASK) >= i_size_read(inode))
return __reserve_data_block(cow_inode, index, blk_addr, goto reserve_block;
node_changed);
/* Look for the block in COW inode first */ /* Look for the block in COW inode first */
err = __find_data_block(cow_inode, index, blk_addr); err = __find_data_block(cow_inode, index, blk_addr);
...@@ -3425,10 +3424,12 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi, ...@@ -3425,10 +3424,12 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
if (err) if (err)
return err; return err;
reserve_block:
/* Finally, we should reserve a new block in COW inode for the update */ /* Finally, we should reserve a new block in COW inode for the update */
err = __reserve_data_block(cow_inode, index, blk_addr, node_changed); err = __reserve_data_block(cow_inode, index, blk_addr, node_changed);
if (err) if (err)
return err; return err;
inc_atomic_write_cnt(inode);
if (ori_blk_addr != NULL_ADDR) if (ori_blk_addr != NULL_ADDR)
*blk_addr = ori_blk_addr; *blk_addr = ori_blk_addr;
......
...@@ -813,6 +813,8 @@ struct f2fs_inode_info { ...@@ -813,6 +813,8 @@ struct f2fs_inode_info {
unsigned char i_compress_level; /* compress level (lz4hc,zstd) */ unsigned char i_compress_level; /* compress level (lz4hc,zstd) */
unsigned short i_compress_flag; /* compress flag */ unsigned short i_compress_flag; /* compress flag */
unsigned int i_cluster_size; /* cluster size */ unsigned int i_cluster_size; /* cluster size */
unsigned int atomic_write_cnt;
}; };
static inline void get_extent_info(struct extent_info *ext, static inline void get_extent_info(struct extent_info *ext,
...@@ -1813,6 +1815,12 @@ struct f2fs_sb_info { ...@@ -1813,6 +1815,12 @@ struct f2fs_sb_info {
int max_fragment_chunk; /* max chunk size for block fragmentation mode */ int max_fragment_chunk; /* max chunk size for block fragmentation mode */
int max_fragment_hole; /* max hole 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 #ifdef CONFIG_F2FS_FS_COMPRESSION
struct kmem_cache *page_array_slab; /* page array entry */ struct kmem_cache *page_array_slab; /* page array entry */
unsigned int page_array_slab_size; /* default page array slab size */ 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) ...@@ -2427,6 +2435,28 @@ static inline void inode_dec_dirty_pages(struct inode *inode)
dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 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) static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
{ {
return atomic_read(&sbi->nr_pages[count_type]); return atomic_read(&sbi->nr_pages[count_type]);
......
...@@ -2075,6 +2075,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) ...@@ -2075,6 +2075,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
f2fs_update_time(sbi, REQ_TIME); f2fs_update_time(sbi, REQ_TIME);
fi->atomic_write_task = current; fi->atomic_write_task = current;
stat_update_max_atomic_write(inode); stat_update_max_atomic_write(inode);
fi->atomic_write_cnt = 0;
out: out:
inode_unlock(inode); inode_unlock(inode);
mnt_drop_write_file(filp); mnt_drop_write_file(filp);
......
...@@ -196,6 +196,7 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean) ...@@ -196,6 +196,7 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean)
clear_inode_flag(fi->cow_inode, FI_ATOMIC_FILE); clear_inode_flag(fi->cow_inode, FI_ATOMIC_FILE);
iput(fi->cow_inode); iput(fi->cow_inode);
fi->cow_inode = NULL; fi->cow_inode = NULL;
release_atomic_write_cnt(inode);
clear_inode_flag(inode, FI_ATOMIC_FILE); clear_inode_flag(inode, FI_ATOMIC_FILE);
spin_lock(&sbi->inode_lock[ATOMIC_FILE]); spin_lock(&sbi->inode_lock[ATOMIC_FILE]);
...@@ -335,6 +336,11 @@ static int __f2fs_commit_atomic_write(struct inode *inode) ...@@ -335,6 +336,11 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
} }
out: 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); __complete_revoke_list(inode, &revoke_list, ret ? true : false);
return ret; return ret;
......
...@@ -3615,6 +3615,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) ...@@ -3615,6 +3615,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE; sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
sbi->max_fragment_hole = DEF_FRAGMENT_SIZE; sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;
spin_lock_init(&sbi->gc_urgent_high_lock); spin_lock_init(&sbi->gc_urgent_high_lock);
atomic64_set(&sbi->current_atomic_write, 0);
sbi->dir_level = DEF_DIR_LEVEL; sbi->dir_level = DEF_DIR_LEVEL;
sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
......
...@@ -339,6 +339,21 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a, ...@@ -339,6 +339,21 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
sbi->gc_reclaimed_segs[sbi->gc_segment_mode]); sbi->gc_reclaimed_segs[sbi->gc_segment_mode]);
} }
if (!strcmp(a->attr.name, "current_atomic_write")) {
s64 current_write = atomic64_read(&sbi->current_atomic_write);
return sysfs_emit(buf, "%lld\n", current_write);
}
if (!strcmp(a->attr.name, "peak_atomic_write"))
return sysfs_emit(buf, "%lld\n", sbi->peak_atomic_write);
if (!strcmp(a->attr.name, "committed_atomic_block"))
return sysfs_emit(buf, "%llu\n", sbi->committed_atomic_block);
if (!strcmp(a->attr.name, "revoked_atomic_block"))
return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block);
ui = (unsigned int *)(ptr + a->offset); ui = (unsigned int *)(ptr + a->offset);
return sprintf(buf, "%u\n", *ui); return sprintf(buf, "%u\n", *ui);
...@@ -608,6 +623,27 @@ static ssize_t __sbi_store(struct f2fs_attr *a, ...@@ -608,6 +623,27 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count; return count;
} }
if (!strcmp(a->attr.name, "peak_atomic_write")) {
if (t != 0)
return -EINVAL;
sbi->peak_atomic_write = 0;
return count;
}
if (!strcmp(a->attr.name, "committed_atomic_block")) {
if (t != 0)
return -EINVAL;
sbi->committed_atomic_block = 0;
return count;
}
if (!strcmp(a->attr.name, "revoked_atomic_block")) {
if (t != 0)
return -EINVAL;
sbi->revoked_atomic_block = 0;
return count;
}
*ui = (unsigned int)t; *ui = (unsigned int)t;
return count; return count;
...@@ -855,6 +891,12 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs); ...@@ -855,6 +891,12 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole);
/* For atomic write */
F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, current_atomic_write, current_atomic_write);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, peak_atomic_write, peak_atomic_write);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, committed_atomic_block, committed_atomic_block);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block);
#define ATTR_LIST(name) (&f2fs_attr_##name.attr) #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
static struct attribute *f2fs_attrs[] = { static struct attribute *f2fs_attrs[] = {
ATTR_LIST(gc_urgent_sleep_time), ATTR_LIST(gc_urgent_sleep_time),
...@@ -944,6 +986,10 @@ static struct attribute *f2fs_attrs[] = { ...@@ -944,6 +986,10 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(gc_reclaimed_segments), ATTR_LIST(gc_reclaimed_segments),
ATTR_LIST(max_fragment_chunk), ATTR_LIST(max_fragment_chunk),
ATTR_LIST(max_fragment_hole), ATTR_LIST(max_fragment_hole),
ATTR_LIST(current_atomic_write),
ATTR_LIST(peak_atomic_write),
ATTR_LIST(committed_atomic_block),
ATTR_LIST(revoked_atomic_block),
NULL, NULL,
}; };
ATTRIBUTE_GROUPS(f2fs); ATTRIBUTE_GROUPS(f2fs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment