From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pekka Enberg Subject: Re: [PATCH v3 3/4] limit nr_dentries per superblock Date: Mon, 15 Aug 2011 10:12:06 +0300 Message-ID: References: <1313334832-1150-1-git-send-email-glommer@parallels.com> <1313334832-1150-4-git-send-email-glommer@parallels.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, containers@lists.linux-foundation.org, Pavel Emelyanov , Al Viro , Hugh Dickins , Nick Piggin , Andrea Arcangeli , Rik van Riel , Dave Hansen , James Bottomley , David Chinner , Eric Dumazet , Christoph Lameter , David Rientjes To: Glauber Costa Return-path: In-Reply-To: <1313334832-1150-4-git-send-email-glommer@parallels.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Sun, Aug 14, 2011 at 6:13 PM, Glauber Costa = wrote: > This patch lays the foundation for us to limit the dcache size. > Each super block can have only a maximum amount of dentries under its > sub-tree. Allocation fails if we we're over limit and the cache > can't be pruned to free up space for the newcomers. > > Signed-off-by: Glauber Costa > CC: Dave Chinner > CC: Eric Dumazet > --- > =A0fs/dcache.c =A0 =A0 =A0 =A0| =A0 28 ++++++++++++++++++++++++++++ > =A0fs/super.c =A0 =A0 =A0 =A0 | =A0 =A01 + > =A0include/linux/fs.h | =A0 =A01 + > =A03 files changed, 30 insertions(+), 0 deletions(-) > > diff --git a/fs/dcache.c b/fs/dcache.c > index 815d9fd..ddd02a2 100644 > --- a/fs/dcache.c > +++ b/fs/dcache.c > @@ -1180,6 +1180,31 @@ void shrink_dcache_parent(struct dentry * pare= nt) > =A0} > =A0EXPORT_SYMBOL(shrink_dcache_parent); > > +static inline int dcache_mem_check(struct super_block *sb) > +{ > + =A0 =A0 =A0 struct shrink_control sc =3D { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 .gfp_mask =3D GFP_KERNEL, > + =A0 =A0 =A0 }; > + > + =A0 =A0 =A0 if (sb->s_nr_dentry_max =3D=3D INT_MAX) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; > + > + =A0 =A0 =A0 do { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 int nr_dentry; > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 nr_dentry =3D percpu_counter_read_posit= ive(&sb->s_nr_dentry); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nr_dentry > sb->s_nr_dentry_max) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nr_dentry =3D > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 percpu_= counter_sum_positive(&sb->s_nr_dentry); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nr_dentry < sb->s_nr_dentry_max) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; > + > + =A0 =A0 =A0 /* nr_pages =3D 1, lru_pages =3D 0 should get delta ~ 2= */ > + =A0 =A0 =A0 } while (shrink_one_shrinker(&sb->s_shrink, &sc, 1, 0))= ; > + > + =A0 =A0 =A0 return -ENOMEM; > +} > + > =A0/** > =A0* __d_alloc =A0 - =A0 =A0 =A0 allocate a dcache entry > =A0* @sb: filesystem it will belong to > @@ -1195,6 +1220,9 @@ struct dentry *__d_alloc(struct super_block *sb= , const struct qstr *name) > =A0 =A0 =A0 =A0struct dentry *dentry; > =A0 =A0 =A0 =A0char *dname; > > + =A0 =A0 =A0 if (dcache_mem_check(sb)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL; > + > =A0 =A0 =A0 =A0dentry =3D kmem_cache_alloc(dentry_cache, GFP_KERNEL); > =A0 =A0 =A0 =A0if (!dentry) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return NULL; > diff --git a/fs/super.c b/fs/super.c > index e95ac4f..3db40fb 100644 > --- a/fs/super.c > +++ b/fs/super.c > @@ -121,6 +121,7 @@ static struct super_block *alloc_super(struct fil= e_system_type *type) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0percpu_counter_init(&s->s_nr_dentry, 0= ); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 s->s_nr_dentry_max =3D INT_MAX; > > =A0#ifdef CONFIG_SMP > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0s->s_files =3D alloc_percpu(struct lis= t_head); > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 8150f52..bc773c3 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -1400,6 +1400,7 @@ struct super_block { > =A0 =A0 =A0 =A0int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s_nr_dentr= y_unused; =A0 =A0 /* # of dentry on lru */ > > =A0 =A0 =A0 =A0struct percpu_counter =A0 s_nr_dentry; =A0 =A0 =A0 =A0= =A0 =A0/* # of dentry on this sb */ > + =A0 =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s_nr_dentry= _max; =A0 =A0 =A0 =A0/* max # of dentry on this sb*/ > > =A0 =A0 =A0 =A0/* s_inode_lru_lock protects s_inode_lru and s_nr_inod= es_unused */ > =A0 =A0 =A0 =A0spinlock_t =A0 =A0 =A0 =A0 =A0 =A0 =A0s_inode_lru_lock= ____cacheline_aligned_in_smp; We track the total number of objects in mm/slub.c when CONFIG_SLUB_DEBUG is enabled (look for n->total_objects in the code). Have you considered extending that for this purpose? Pekka