f2fs: use atomic_t to record hit ratio info of extent cache
authorChao Yu <chao2.yu@samsung.com>
Wed, 15 Jul 2015 09:29:49 +0000 (17:29 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 5 Aug 2015 15:08:06 +0000 (08:08 -0700)
Variables for recording extent cache ratio info were updated without
protection, this patch tries to alter them to atomic_t type for more
accurate stat.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/debug.c
fs/f2fs/extent_cache.c
fs/f2fs/f2fs.h

index 2aeaf4e214db5ad922a82df7819af266c757e08b..bc215fd6c402d6f99cfa6c4bc5788d573fabc647 100644 (file)
@@ -33,8 +33,8 @@ static void update_general_status(struct f2fs_sb_info *sbi)
        int i;
 
        /* validation check of the segment numbers */
-       si->hit_ext = sbi->read_hit_ext;
-       si->total_ext = sbi->total_hit_ext;
+       si->hit_ext = atomic_read(&sbi->read_hit_ext);
+       si->total_ext = atomic_read(&sbi->total_hit_ext);
        si->ext_tree = sbi->total_ext_tree;
        si->ext_node = atomic_read(&sbi->total_ext_node);
        si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
@@ -369,6 +369,9 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)
        si->sbi = sbi;
        sbi->stat_info = si;
 
+       atomic_set(&sbi->total_hit_ext, 0);
+       atomic_set(&sbi->read_hit_ext, 0);
+
        atomic_set(&sbi->inline_xattr, 0);
        atomic_set(&sbi->inline_inode, 0);
        atomic_set(&sbi->inline_dir, 0);
index 5f78fc1e818af44971f5fee13c2d0ed1c6153692..362df8cd54d443a3a6d494e99d1f9acada1d9fef 100644 (file)
@@ -279,7 +279,7 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
                        et->largest.fofs + et->largest.len > pgofs) {
                *ei = et->largest;
                ret = true;
-               stat_inc_read_hit(sbi->sb);
+               stat_inc_read_hit(sbi);
                goto out;
        }
 
@@ -292,10 +292,10 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
                et->cached_en = en;
                spin_unlock(&sbi->extent_lock);
                ret = true;
-               stat_inc_read_hit(sbi->sb);
+               stat_inc_read_hit(sbi);
        }
 out:
-       stat_inc_total_hit(sbi->sb);
+       stat_inc_total_hit(sbi);
        read_unlock(&et->lock);
 
        trace_f2fs_lookup_extent_tree_end(inode, pgofs, ei);
index b18b8526771128b39264058234d80b735407fdf3..38ba525c3d6f3dbfb44f4e6818896a814afc8acf 100644 (file)
@@ -781,7 +781,8 @@ struct f2fs_sb_info {
        unsigned int segment_count[2];          /* # of allocated segments */
        unsigned int block_count[2];            /* # of allocated blocks */
        atomic_t inplace_count;         /* # of inplace update */
-       int total_hit_ext, read_hit_ext;        /* extent cache hit ratio */
+       atomic_t total_hit_ext;                 /* # of lookup extent cache */
+       atomic_t read_hit_ext;                  /* # of hit extent cache */
        atomic_t inline_xattr;                  /* # of inline_xattr inodes */
        atomic_t inline_inode;                  /* # of inline_data inodes */
        atomic_t inline_dir;                    /* # of inline_dentry inodes */
@@ -1837,8 +1838,8 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
 #define stat_inc_bggc_count(sbi)       ((sbi)->bg_gc++)
 #define stat_inc_dirty_dir(sbi)                ((sbi)->n_dirty_dirs++)
 #define stat_dec_dirty_dir(sbi)                ((sbi)->n_dirty_dirs--)
-#define stat_inc_total_hit(sb)         ((F2FS_SB(sb))->total_hit_ext++)
-#define stat_inc_read_hit(sb)          ((F2FS_SB(sb))->read_hit_ext++)
+#define stat_inc_total_hit(sbi)                (atomic_inc(&(sbi)->total_hit_ext))
+#define stat_inc_read_hit(sbi)         (atomic_inc(&(sbi)->read_hit_ext))
 #define stat_inc_inline_xattr(inode)                                   \
        do {                                                            \
                if (f2fs_has_inline_xattr(inode))                       \