f2fs: use percpu_counter for alloc_valid_block_count
authorJaegeuk Kim <jaegeuk@kernel.org>
Mon, 16 May 2016 18:06:50 +0000 (11:06 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 18 May 2016 20:57:29 +0000 (13:57 -0700)
This patch uses percpu_count for sbi->alloc_valid_block_count.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/recovery.c
fs/f2fs/super.c

index 447e2a9..cf79598 100644 (file)
@@ -1079,7 +1079,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
        /* update user_block_counts */
        sbi->last_valid_block_count = sbi->total_valid_block_count;
-       sbi->alloc_valid_block_count = 0;
+       percpu_counter_set(&sbi->alloc_valid_block_count, 0);
 
        /* Here, we only have one bio having CP pack */
        sync_meta_pages(sbi, META_FLUSH, LONG_MAX);
index 3f1c710..c8833c8 100644 (file)
@@ -808,7 +808,6 @@ struct f2fs_sb_info {
 
        block_t user_block_count;               /* # of user blocks */
        block_t total_valid_block_count;        /* # of valid blocks */
-       block_t alloc_valid_block_count;        /* # of allocated blocks */
        block_t discard_blks;                   /* discard command candidats */
        block_t last_valid_block_count;         /* for recovery */
        u32 s_next_generation;                  /* for NFS support */
@@ -816,6 +815,8 @@ struct f2fs_sb_info {
 
        /* # of pages, see count_type */
        struct percpu_counter nr_pages[NR_COUNT_TYPE];
+       /* # of allocated blocks */
+       struct percpu_counter alloc_valid_block_count;
 
        struct f2fs_mount_info mount_opt;       /* mount options */
 
@@ -1141,8 +1142,9 @@ static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
        inode->i_blocks += *count;
        sbi->total_valid_block_count =
                sbi->total_valid_block_count + (block_t)(*count);
-       sbi->alloc_valid_block_count += (block_t)(*count);
        spin_unlock(&sbi->stat_lock);
+
+       percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
        return true;
 }
 
@@ -1292,11 +1294,11 @@ static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
        if (inode)
                inode->i_blocks++;
 
-       sbi->alloc_valid_block_count++;
        sbi->total_valid_node_count++;
        sbi->total_valid_block_count++;
        spin_unlock(&sbi->stat_lock);
 
+       percpu_counter_inc(&sbi->alloc_valid_block_count);
        return true;
 }
 
index 6303b2a..f89b70e 100644 (file)
@@ -49,8 +49,9 @@ static struct kmem_cache *fsync_entry_slab;
 
 bool space_for_roll_forward(struct f2fs_sb_info *sbi)
 {
-       if (sbi->last_valid_block_count + sbi->alloc_valid_block_count
-                       > sbi->user_block_count)
+       s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count);
+
+       if (sbi->last_valid_block_count + nalloc > sbi->user_block_count)
                return false;
        return true;
 }
index 0ff862b..43e3e9c 100644 (file)
@@ -617,6 +617,7 @@ static void destroy_percpu_info(struct f2fs_sb_info *sbi)
 
        for (i = 0; i < NR_COUNT_TYPE; i++)
                percpu_counter_destroy(&sbi->nr_pages[i]);
+       percpu_counter_destroy(&sbi->alloc_valid_block_count);
 }
 
 static void f2fs_put_super(struct super_block *sb)
@@ -1382,7 +1383,9 @@ static int init_percpu_info(struct f2fs_sb_info *sbi)
                if (err)
                        return err;
        }
-       return 0;
+
+       return percpu_counter_init(&sbi->alloc_valid_block_count, 0,
+                                                               GFP_KERNEL);
 }
 
 /*
@@ -1601,7 +1604,7 @@ try_onemore:
        sbi->total_valid_block_count =
                                le64_to_cpu(sbi->ckpt->valid_block_count);
        sbi->last_valid_block_count = sbi->total_valid_block_count;
-       sbi->alloc_valid_block_count = 0;
+
        for (i = 0; i < NR_INODE_TYPE; i++) {
                INIT_LIST_HEAD(&sbi->inode_list[i]);
                spin_lock_init(&sbi->inode_lock[i]);