From mboxrd@z Thu Jan 1 00:00:00 1970 From: Glauber Costa Subject: [PATCH v5 03/31] dcache: convert dentry_stat.nr_unused to per-cpu counters Date: Thu, 9 May 2013 10:06:20 +0400 Message-ID: <1368079608-5611-4-git-send-email-glommer@openvz.org> References: <1368079608-5611-1-git-send-email-glommer@openvz.org> Cc: Andrew Morton , Mel Gorman , , , Johannes Weiner , Michal Hocko , hughd@google.com, Greg Thelen , , Dave Chinner To: Return-path: In-Reply-To: <1368079608-5611-1-git-send-email-glommer@openvz.org> Sender: owner-linux-mm@kvack.org List-Id: linux-fsdevel.vger.kernel.org From: Dave Chinner Before we split up the dcache_lru_lock, the unused dentry counter needs to be made independent of the global dcache_lru_lock. Convert it to per-cpu counters to do this. [ v5: comment about possible cpus ] Signed-off-by: Dave Chinner Reviewed-by: Christoph Hellwig Acked-by: Mel Gorman --- fs/dcache.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index e689268..5000595 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -118,8 +118,10 @@ struct dentry_stat_t dentry_stat = { }; static DEFINE_PER_CPU(unsigned int, nr_dentry); +static DEFINE_PER_CPU(unsigned int, nr_dentry_unused); #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) +/* scan possible cpus instead of online and avoid worrying about CPU hotplug. */ static int get_nr_dentry(void) { int i; @@ -129,10 +131,20 @@ static int get_nr_dentry(void) return sum < 0 ? 0 : sum; } +static int get_nr_dentry_unused(void) +{ + int i; + int sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(nr_dentry_unused, i); + return sum < 0 ? 0 : sum; +} + int proc_nr_dentry(ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { dentry_stat.nr_dentry = get_nr_dentry(); + dentry_stat.nr_unused = get_nr_dentry_unused(); return proc_dointvec(table, write, buffer, lenp, ppos); } #endif @@ -312,7 +324,7 @@ static void dentry_lru_add(struct dentry *dentry) spin_lock(&dcache_lru_lock); list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); dentry->d_sb->s_nr_dentry_unused++; - dentry_stat.nr_unused++; + this_cpu_inc(nr_dentry_unused); spin_unlock(&dcache_lru_lock); } } @@ -322,7 +334,7 @@ static void __dentry_lru_del(struct dentry *dentry) list_del_init(&dentry->d_lru); dentry->d_flags &= ~DCACHE_SHRINK_LIST; dentry->d_sb->s_nr_dentry_unused--; - dentry_stat.nr_unused--; + this_cpu_dec(nr_dentry_unused); } /* @@ -360,7 +372,7 @@ static void dentry_lru_move_list(struct dentry *dentry, struct list_head *list) if (list_empty(&dentry->d_lru)) { list_add_tail(&dentry->d_lru, list); dentry->d_sb->s_nr_dentry_unused++; - dentry_stat.nr_unused++; + this_cpu_inc(nr_dentry_unused); } else { list_move_tail(&dentry->d_lru, list); } -- 1.8.1.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Glauber Costa Subject: [PATCH v5 03/31] dcache: convert dentry_stat.nr_unused to per-cpu counters Date: Thu, 9 May 2013 10:06:20 +0400 Message-ID: <1368079608-5611-4-git-send-email-glommer@openvz.org> References: <1368079608-5611-1-git-send-email-glommer@openvz.org> Return-path: In-Reply-To: <1368079608-5611-1-git-send-email-glommer@openvz.org> Sender: owner-linux-mm@kvack.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-mm@kvack.org Cc: Andrew Morton , Mel Gorman , cgroups@vger.kernel.org, kamezawa.hiroyu@jp.fujitsu.com, Johannes Weiner , Michal Hocko , hughd@google.com, Greg Thelen , linux-fsdevel@vger.kernel.org, Dave Chinner From: Dave Chinner Before we split up the dcache_lru_lock, the unused dentry counter needs to be made independent of the global dcache_lru_lock. Convert it to per-cpu counters to do this. [ v5: comment about possible cpus ] Signed-off-by: Dave Chinner Reviewed-by: Christoph Hellwig Acked-by: Mel Gorman --- fs/dcache.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index e689268..5000595 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -118,8 +118,10 @@ struct dentry_stat_t dentry_stat = { }; static DEFINE_PER_CPU(unsigned int, nr_dentry); +static DEFINE_PER_CPU(unsigned int, nr_dentry_unused); #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) +/* scan possible cpus instead of online and avoid worrying about CPU hotplug. */ static int get_nr_dentry(void) { int i; @@ -129,10 +131,20 @@ static int get_nr_dentry(void) return sum < 0 ? 0 : sum; } +static int get_nr_dentry_unused(void) +{ + int i; + int sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(nr_dentry_unused, i); + return sum < 0 ? 0 : sum; +} + int proc_nr_dentry(ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { dentry_stat.nr_dentry = get_nr_dentry(); + dentry_stat.nr_unused = get_nr_dentry_unused(); return proc_dointvec(table, write, buffer, lenp, ppos); } #endif @@ -312,7 +324,7 @@ static void dentry_lru_add(struct dentry *dentry) spin_lock(&dcache_lru_lock); list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); dentry->d_sb->s_nr_dentry_unused++; - dentry_stat.nr_unused++; + this_cpu_inc(nr_dentry_unused); spin_unlock(&dcache_lru_lock); } } @@ -322,7 +334,7 @@ static void __dentry_lru_del(struct dentry *dentry) list_del_init(&dentry->d_lru); dentry->d_flags &= ~DCACHE_SHRINK_LIST; dentry->d_sb->s_nr_dentry_unused--; - dentry_stat.nr_unused--; + this_cpu_dec(nr_dentry_unused); } /* @@ -360,7 +372,7 @@ static void dentry_lru_move_list(struct dentry *dentry, struct list_head *list) if (list_empty(&dentry->d_lru)) { list_add_tail(&dentry->d_lru, list); dentry->d_sb->s_nr_dentry_unused++; - dentry_stat.nr_unused++; + this_cpu_inc(nr_dentry_unused); } else { list_move_tail(&dentry->d_lru, list); } -- 1.8.1.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org