f2fs: change to use atomic_t type form sbi.atomic_files
authorChao Yu <chao@kernel.org>
Tue, 4 Oct 2022 01:41:02 +0000 (09:41 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 7 Oct 2022 19:57:26 +0000 (12:57 -0700)
inode_lock[ATOMIC_FILE] was used for protecting sbi->atomic_files,
update atomic_files variable's type to atomic_t instead of unsigned
int, then inode_lock[ATOMIC_FILE] can be obsoleted.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/debug.c
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/segment.c

index 7a9dd23191551e594ce854439fce6db965cfb853..a216dcdf69418e7583f48e92db963ed1ab4d0980 100644 (file)
@@ -91,7 +91,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
        si->ndirty_files = sbi->ndirty_inode[FILE_INODE];
        si->nquota_files = sbi->nquota_files;
        si->ndirty_all = sbi->ndirty_inode[DIRTY_META];
-       si->aw_cnt = sbi->atomic_files;
+       si->aw_cnt = atomic_read(&sbi->atomic_files);
        si->max_aw_cnt = atomic_read(&sbi->max_aw_cnt);
        si->nr_dio_read = get_pages(sbi, F2FS_DIO_READ);
        si->nr_dio_write = get_pages(sbi, F2FS_DIO_WRITE);
@@ -611,6 +611,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)
        atomic_set(&sbi->compr_inode, 0);
        atomic64_set(&sbi->compr_blocks, 0);
        atomic_set(&sbi->swapfile_inode, 0);
+       atomic_set(&sbi->atomic_files, 0);
        atomic_set(&sbi->inplace_count, 0);
        for (i = META_CP; i < META_MAX; i++)
                atomic_set(&sbi->meta_count[i], 0);
index 134581defe4a889f45110b4b2f5c764445544491..e7e750e6b3321f919cb72731ae442b6a0891070a 100644 (file)
@@ -1257,7 +1257,6 @@ enum inode_type {
        DIR_INODE,                      /* for dirty dir inode */
        FILE_INODE,                     /* for dirty regular/symlink inode */
        DIRTY_META,                     /* for all dirtied inode metadata */
-       ATOMIC_FILE,                    /* for all atomic files */
        NR_INODE_TYPE,
 };
 
@@ -1739,7 +1738,6 @@ struct f2fs_sb_info {
        unsigned int gc_urgent_high_remaining;  /* remaining trial count for GC_URGENT_HIGH */
 
        /* for skip statistic */
-       unsigned int atomic_files;              /* # of opened atomic file */
        unsigned long long skipped_gc_rwsem;            /* FG_GC only */
 
        /* threshold for gc trials on pinned files */
@@ -1771,6 +1769,7 @@ struct f2fs_sb_info {
        atomic_t compr_inode;                   /* # of compressed inodes */
        atomic64_t compr_blocks;                /* # of compressed blocks */
        atomic_t swapfile_inode;                /* # of swapfile inodes */
+       atomic_t atomic_files;                  /* # of opened atomic file */
        atomic_t max_aw_cnt;                    /* max # of atomic writes */
        unsigned int io_skip_bggc;              /* skip background gc for in-flight IO */
        unsigned int other_skip_bggc;           /* skip background gc for other reasons */
@@ -3970,6 +3969,10 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
                (atomic_inc(&F2FS_I_SB(inode)->swapfile_inode))
 #define stat_dec_swapfile_inode(inode)                                 \
                (atomic_dec(&F2FS_I_SB(inode)->swapfile_inode))
+#define stat_inc_atomic_inode(inode)                                   \
+                       (atomic_inc(&F2FS_I_SB(inode)->atomic_files))
+#define stat_dec_atomic_inode(inode)                                   \
+                       (atomic_dec(&F2FS_I_SB(inode)->atomic_files))
 #define stat_inc_meta_count(sbi, blkaddr)                              \
        do {                                                            \
                if (blkaddr < SIT_I(sbi)->sit_base_addr)                \
@@ -3989,7 +3992,7 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
                (atomic_inc(&(sbi)->inplace_count))
 #define stat_update_max_atomic_write(inode)                            \
        do {                                                            \
-               int cur = F2FS_I_SB(inode)->atomic_files;       \
+               int cur = atomic_read(&F2FS_I_SB(inode)->atomic_files); \
                int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt);   \
                if (cur > max)                                          \
                        atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \
@@ -4056,6 +4059,8 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
 #define stat_sub_compr_blocks(inode, blocks)           do { } while (0)
 #define stat_inc_swapfile_inode(inode)                 do { } while (0)
 #define stat_dec_swapfile_inode(inode)                 do { } while (0)
+#define stat_inc_atomic_inode(inode)                   do { } while (0)
+#define stat_dec_atomic_inode(inode)                   do { } while (0)
 #define stat_update_max_atomic_write(inode)            do { } while (0)
 #define stat_inc_meta_count(sbi, blkaddr)              do { } while (0)
 #define stat_inc_seg_type(sbi, curseg)                 do { } while (0)
index 7b3ed4a9bb46e0a3a2bd28a2f819c42a83113dc9..ec9ee0f6d502db42d2d0c75f6066d86fea9f946f 100644 (file)
@@ -2051,9 +2051,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
        }
        f2fs_i_size_write(fi->cow_inode, i_size_read(inode));
 
-       spin_lock(&sbi->inode_lock[ATOMIC_FILE]);
-       sbi->atomic_files++;
-       spin_unlock(&sbi->inode_lock[ATOMIC_FILE]);
+       stat_inc_atomic_inode(inode);
 
        set_inode_flag(inode, FI_ATOMIC_FILE);
        set_inode_flag(fi->cow_inode, FI_COW_FILE);
index d7b13127b0b8a5096f1d6da92802b9c31b5191ce..289bcb7ca30095bec8ca4a8283a6d23678e2b080 100644 (file)
@@ -187,7 +187,6 @@ bool f2fs_need_SSR(struct f2fs_sb_info *sbi)
 
 void f2fs_abort_atomic_write(struct inode *inode, bool clean)
 {
-       struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct f2fs_inode_info *fi = F2FS_I(inode);
 
        if (!f2fs_is_atomic_file(inode))
@@ -200,10 +199,7 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean)
        fi->cow_inode = NULL;
        release_atomic_write_cnt(inode);
        clear_inode_flag(inode, FI_ATOMIC_FILE);
-
-       spin_lock(&sbi->inode_lock[ATOMIC_FILE]);
-       sbi->atomic_files--;
-       spin_unlock(&sbi->inode_lock[ATOMIC_FILE]);
+       stat_dec_atomic_inode(inode);
 }
 
 static int __replace_atomic_write_block(struct inode *inode, pgoff_t index,