Commit 513c5f37 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: use percpu_counter for total_valid_inode_count

This patch uses percpu_counter to avoid stat_lock.
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 41382ec4
...@@ -801,7 +801,6 @@ struct f2fs_sb_info { ...@@ -801,7 +801,6 @@ struct f2fs_sb_info {
unsigned int total_sections; /* total section count */ unsigned int total_sections; /* total section count */
unsigned int total_node_count; /* total node block count */ unsigned int total_node_count; /* total node block count */
unsigned int total_valid_node_count; /* valid node block count */ unsigned int total_valid_node_count; /* valid node block count */
unsigned int total_valid_inode_count; /* valid inode count */
loff_t max_file_blocks; /* max block index of file */ loff_t max_file_blocks; /* max block index of file */
int active_logs; /* # of active logs */ int active_logs; /* # of active logs */
int dir_level; /* directory level */ int dir_level; /* directory level */
...@@ -818,6 +817,9 @@ struct f2fs_sb_info { ...@@ -818,6 +817,9 @@ struct f2fs_sb_info {
/* # of allocated blocks */ /* # of allocated blocks */
struct percpu_counter alloc_valid_block_count; struct percpu_counter alloc_valid_block_count;
/* valid inode count */
struct percpu_counter total_valid_inode_count;
struct f2fs_mount_info mount_opt; /* mount options */ struct f2fs_mount_info mount_opt; /* mount options */
/* for cleaning operations */ /* for cleaning operations */
...@@ -1325,23 +1327,17 @@ static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) ...@@ -1325,23 +1327,17 @@ static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
{ {
spin_lock(&sbi->stat_lock); percpu_counter_inc(&sbi->total_valid_inode_count);
f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
sbi->total_valid_inode_count++;
spin_unlock(&sbi->stat_lock);
} }
static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
{ {
spin_lock(&sbi->stat_lock); percpu_counter_dec(&sbi->total_valid_inode_count);
f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
sbi->total_valid_inode_count--;
spin_unlock(&sbi->stat_lock);
} }
static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
{ {
return sbi->total_valid_inode_count; return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
} }
static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
......
...@@ -618,6 +618,7 @@ static void destroy_percpu_info(struct f2fs_sb_info *sbi) ...@@ -618,6 +618,7 @@ static void destroy_percpu_info(struct f2fs_sb_info *sbi)
for (i = 0; i < NR_COUNT_TYPE; i++) for (i = 0; i < NR_COUNT_TYPE; i++)
percpu_counter_destroy(&sbi->nr_pages[i]); percpu_counter_destroy(&sbi->nr_pages[i]);
percpu_counter_destroy(&sbi->alloc_valid_block_count); percpu_counter_destroy(&sbi->alloc_valid_block_count);
percpu_counter_destroy(&sbi->total_valid_inode_count);
} }
static void f2fs_put_super(struct super_block *sb) static void f2fs_put_super(struct super_block *sb)
...@@ -1384,7 +1385,11 @@ static int init_percpu_info(struct f2fs_sb_info *sbi) ...@@ -1384,7 +1385,11 @@ static int init_percpu_info(struct f2fs_sb_info *sbi)
return err; return err;
} }
return percpu_counter_init(&sbi->alloc_valid_block_count, 0, err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL);
if (err)
return err;
return percpu_counter_init(&sbi->total_valid_inode_count, 0,
GFP_KERNEL); GFP_KERNEL);
} }
...@@ -1598,8 +1603,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1598,8 +1603,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
sbi->total_valid_node_count = sbi->total_valid_node_count =
le32_to_cpu(sbi->ckpt->valid_node_count); le32_to_cpu(sbi->ckpt->valid_node_count);
sbi->total_valid_inode_count = percpu_counter_set(&sbi->total_valid_inode_count,
le32_to_cpu(sbi->ckpt->valid_inode_count); le32_to_cpu(sbi->ckpt->valid_inode_count));
sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
sbi->total_valid_block_count = sbi->total_valid_block_count =
le64_to_cpu(sbi->ckpt->valid_block_count); le64_to_cpu(sbi->ckpt->valid_block_count);
......
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