提交 86c8749e 编写于 作者: N Nick Piggin

vfs: revert per-cpu nr_unused counters for dentry and inodes

The nr_unused counters count the number of objects on an LRU, and as such they
are synchronized with LRU object insertion and removal and scanning, and
protected under the LRU lock.

Making it per-cpu does not actually get any concurrency improvements because of
this lock, and summing the counter is much slower, and
incrementing/decrementing it costs more code size and is slower too.

These counters should stay per-LRU, which currently means global.
Signed-off-by: NNick Piggin <npiggin@kernel.dk>
上级 ccd35fb9
...@@ -68,14 +68,12 @@ struct dentry_stat_t dentry_stat = { ...@@ -68,14 +68,12 @@ struct dentry_stat_t dentry_stat = {
}; };
static struct percpu_counter nr_dentry __cacheline_aligned_in_smp; static struct percpu_counter nr_dentry __cacheline_aligned_in_smp;
static struct percpu_counter nr_dentry_unused __cacheline_aligned_in_smp;
#if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
int proc_nr_dentry(ctl_table *table, int write, void __user *buffer, int proc_nr_dentry(ctl_table *table, int write, void __user *buffer,
size_t *lenp, loff_t *ppos) size_t *lenp, loff_t *ppos)
{ {
dentry_stat.nr_dentry = percpu_counter_sum_positive(&nr_dentry); dentry_stat.nr_dentry = percpu_counter_sum_positive(&nr_dentry);
dentry_stat.nr_unused = percpu_counter_sum_positive(&nr_dentry_unused);
return proc_dointvec(table, write, buffer, lenp, ppos); return proc_dointvec(table, write, buffer, lenp, ppos);
} }
#endif #endif
...@@ -140,7 +138,7 @@ static void dentry_lru_add(struct dentry *dentry) ...@@ -140,7 +138,7 @@ static void dentry_lru_add(struct dentry *dentry)
if (list_empty(&dentry->d_lru)) { if (list_empty(&dentry->d_lru)) {
list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
dentry->d_sb->s_nr_dentry_unused++; dentry->d_sb->s_nr_dentry_unused++;
percpu_counter_inc(&nr_dentry_unused); dentry_stat.nr_unused++;
} }
} }
...@@ -149,7 +147,7 @@ static void dentry_lru_del(struct dentry *dentry) ...@@ -149,7 +147,7 @@ static void dentry_lru_del(struct dentry *dentry)
if (!list_empty(&dentry->d_lru)) { if (!list_empty(&dentry->d_lru)) {
list_del_init(&dentry->d_lru); list_del_init(&dentry->d_lru);
dentry->d_sb->s_nr_dentry_unused--; dentry->d_sb->s_nr_dentry_unused--;
percpu_counter_dec(&nr_dentry_unused); dentry_stat.nr_unused--;
} }
} }
...@@ -158,7 +156,7 @@ static void dentry_lru_move_tail(struct dentry *dentry) ...@@ -158,7 +156,7 @@ static void dentry_lru_move_tail(struct dentry *dentry)
if (list_empty(&dentry->d_lru)) { if (list_empty(&dentry->d_lru)) {
list_add_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); list_add_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
dentry->d_sb->s_nr_dentry_unused++; dentry->d_sb->s_nr_dentry_unused++;
percpu_counter_inc(&nr_dentry_unused); dentry_stat.nr_unused++;
} else { } else {
list_move_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); list_move_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
} }
...@@ -546,7 +544,7 @@ static void prune_dcache(int count) ...@@ -546,7 +544,7 @@ static void prune_dcache(int count)
{ {
struct super_block *sb, *p = NULL; struct super_block *sb, *p = NULL;
int w_count; int w_count;
int unused = percpu_counter_sum_positive(&nr_dentry_unused); int unused = dentry_stat.nr_unused;
int prune_ratio; int prune_ratio;
int pruned; int pruned;
...@@ -908,16 +906,13 @@ EXPORT_SYMBOL(shrink_dcache_parent); ...@@ -908,16 +906,13 @@ EXPORT_SYMBOL(shrink_dcache_parent);
*/ */
static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
{ {
int nr_unused;
if (nr) { if (nr) {
if (!(gfp_mask & __GFP_FS)) if (!(gfp_mask & __GFP_FS))
return -1; return -1;
prune_dcache(nr); prune_dcache(nr);
} }
nr_unused = percpu_counter_sum_positive(&nr_dentry_unused); return (dentry_stat.nr_unused / 100) * sysctl_vfs_cache_pressure;
return (nr_unused / 100) * sysctl_vfs_cache_pressure;
} }
static struct shrinker dcache_shrinker = { static struct shrinker dcache_shrinker = {
...@@ -2424,7 +2419,6 @@ static void __init dcache_init(void) ...@@ -2424,7 +2419,6 @@ static void __init dcache_init(void)
int loop; int loop;
percpu_counter_init(&nr_dentry, 0); percpu_counter_init(&nr_dentry, 0);
percpu_counter_init(&nr_dentry_unused, 0);
/* /*
* A constructor could be added for stable state like the lists, * A constructor could be added for stable state like the lists,
......
...@@ -103,7 +103,6 @@ static DECLARE_RWSEM(iprune_sem); ...@@ -103,7 +103,6 @@ static DECLARE_RWSEM(iprune_sem);
struct inodes_stat_t inodes_stat; struct inodes_stat_t inodes_stat;
static struct percpu_counter nr_inodes __cacheline_aligned_in_smp; static struct percpu_counter nr_inodes __cacheline_aligned_in_smp;
static struct percpu_counter nr_inodes_unused __cacheline_aligned_in_smp;
static struct kmem_cache *inode_cachep __read_mostly; static struct kmem_cache *inode_cachep __read_mostly;
...@@ -114,7 +113,7 @@ static inline int get_nr_inodes(void) ...@@ -114,7 +113,7 @@ static inline int get_nr_inodes(void)
static inline int get_nr_inodes_unused(void) static inline int get_nr_inodes_unused(void)
{ {
return percpu_counter_sum_positive(&nr_inodes_unused); return inodes_stat.nr_unused;
} }
int get_nr_dirty_inodes(void) int get_nr_dirty_inodes(void)
...@@ -132,7 +131,6 @@ int proc_nr_inodes(ctl_table *table, int write, ...@@ -132,7 +131,6 @@ int proc_nr_inodes(ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos) void __user *buffer, size_t *lenp, loff_t *ppos)
{ {
inodes_stat.nr_inodes = get_nr_inodes(); inodes_stat.nr_inodes = get_nr_inodes();
inodes_stat.nr_unused = get_nr_inodes_unused();
return proc_dointvec(table, write, buffer, lenp, ppos); return proc_dointvec(table, write, buffer, lenp, ppos);
} }
#endif #endif
...@@ -335,7 +333,7 @@ static void inode_lru_list_add(struct inode *inode) ...@@ -335,7 +333,7 @@ static void inode_lru_list_add(struct inode *inode)
{ {
if (list_empty(&inode->i_lru)) { if (list_empty(&inode->i_lru)) {
list_add(&inode->i_lru, &inode_lru); list_add(&inode->i_lru, &inode_lru);
percpu_counter_inc(&nr_inodes_unused); inodes_stat.nr_unused++;
} }
} }
...@@ -343,7 +341,7 @@ static void inode_lru_list_del(struct inode *inode) ...@@ -343,7 +341,7 @@ static void inode_lru_list_del(struct inode *inode)
{ {
if (!list_empty(&inode->i_lru)) { if (!list_empty(&inode->i_lru)) {
list_del_init(&inode->i_lru); list_del_init(&inode->i_lru);
percpu_counter_dec(&nr_inodes_unused); inodes_stat.nr_unused--;
} }
} }
...@@ -513,7 +511,7 @@ void evict_inodes(struct super_block *sb) ...@@ -513,7 +511,7 @@ void evict_inodes(struct super_block *sb)
list_move(&inode->i_lru, &dispose); list_move(&inode->i_lru, &dispose);
list_del_init(&inode->i_wb_list); list_del_init(&inode->i_wb_list);
if (!(inode->i_state & (I_DIRTY | I_SYNC))) if (!(inode->i_state & (I_DIRTY | I_SYNC)))
percpu_counter_dec(&nr_inodes_unused); inodes_stat.nr_unused--;
} }
spin_unlock(&inode_lock); spin_unlock(&inode_lock);
...@@ -554,7 +552,7 @@ int invalidate_inodes(struct super_block *sb) ...@@ -554,7 +552,7 @@ int invalidate_inodes(struct super_block *sb)
list_move(&inode->i_lru, &dispose); list_move(&inode->i_lru, &dispose);
list_del_init(&inode->i_wb_list); list_del_init(&inode->i_wb_list);
if (!(inode->i_state & (I_DIRTY | I_SYNC))) if (!(inode->i_state & (I_DIRTY | I_SYNC)))
percpu_counter_dec(&nr_inodes_unused); inodes_stat.nr_unused--;
} }
spin_unlock(&inode_lock); spin_unlock(&inode_lock);
...@@ -616,7 +614,7 @@ static void prune_icache(int nr_to_scan) ...@@ -616,7 +614,7 @@ static void prune_icache(int nr_to_scan)
if (atomic_read(&inode->i_count) || if (atomic_read(&inode->i_count) ||
(inode->i_state & ~I_REFERENCED)) { (inode->i_state & ~I_REFERENCED)) {
list_del_init(&inode->i_lru); list_del_init(&inode->i_lru);
percpu_counter_dec(&nr_inodes_unused); inodes_stat.nr_unused--;
continue; continue;
} }
...@@ -650,7 +648,7 @@ static void prune_icache(int nr_to_scan) ...@@ -650,7 +648,7 @@ static void prune_icache(int nr_to_scan)
*/ */
list_move(&inode->i_lru, &freeable); list_move(&inode->i_lru, &freeable);
list_del_init(&inode->i_wb_list); list_del_init(&inode->i_wb_list);
percpu_counter_dec(&nr_inodes_unused); inodes_stat.nr_unused--;
} }
if (current_is_kswapd()) if (current_is_kswapd())
__count_vm_events(KSWAPD_INODESTEAL, reap); __count_vm_events(KSWAPD_INODESTEAL, reap);
...@@ -1649,7 +1647,6 @@ void __init inode_init(void) ...@@ -1649,7 +1647,6 @@ void __init inode_init(void)
init_once); init_once);
register_shrinker(&icache_shrinker); register_shrinker(&icache_shrinker);
percpu_counter_init(&nr_inodes, 0); percpu_counter_init(&nr_inodes, 0);
percpu_counter_init(&nr_inodes_unused, 0);
/* Hash may have been set up in inode_init_early */ /* Hash may have been set up in inode_init_early */
if (!hashdist) if (!hashdist)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册