From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Emelyanov Subject: [PATCH 6/13] vfs: Turn the nr_dentry into percpu_counter Date: Tue, 03 May 2011 16:17:43 +0400 Message-ID: <4DBFF267.6090807@parallels.com> References: <4DBFF1AD.90303@parallels.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: linux-fsdevel To: Hugh Dickins , Nick Piggin , Andrea Arcangeli , Rik van Riel , Dave Hansen , Alexa Return-path: Received: from mailhub.sw.ru ([195.214.232.25]:14756 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752574Ab1ECMR3 (ORCPT ); Tue, 3 May 2011 08:17:29 -0400 In-Reply-To: <4DBFF1AD.90303@parallels.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The plain percpu was OK when we needed to just accout for the number of dentries allocated. We will have to check that the amount of dentries is kept below some limit, and the percpu_counter is more suitable for this. Signed-off-by: Pavel Emelyanov --- fs/dcache.c | 18 +++++------------- include/linux/dcache.h | 1 + 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 1c56593..fa5b7fa 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -123,22 +123,13 @@ struct dentry_stat_t dentry_stat = { .age_limit = 45, }; -static DEFINE_PER_CPU(unsigned int, nr_dentry); +static struct percpu_counter nr_dentry __cacheline_aligned_in_smp; #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) -static int get_nr_dentry(void) -{ - int i; - int sum = 0; - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry, 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_dentry = percpu_counter_sum_positive(&nr_dentry); return proc_dointvec(table, write, buffer, lenp, ppos); } #endif @@ -159,7 +150,7 @@ static void __d_free(struct rcu_head *head) static void d_free(struct dentry *dentry) { BUG_ON(dentry->d_count); - this_cpu_dec(nr_dentry); + percpu_counter_dec(&nr_dentry); if (dentry->d_op && dentry->d_op->d_release) dentry->d_op->d_release(dentry); @@ -1138,7 +1129,7 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) spin_unlock(&parent->d_lock); } - this_cpu_inc(nr_dentry); + percpu_counter_inc(&nr_dentry); return dentry; } @@ -2847,6 +2838,7 @@ static void __init dcache_init(void) { int loop; + percpu_counter_init(&nr_dentry, 0); /* * A constructor could be added for stable state like the lists, * but it is probably not worth it because of the cache nature diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 8834f58..64848dd 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -9,6 +9,7 @@ #include #include #include +#include struct nameidata; struct path; -- 1.5.5.6