From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761256AbYEJDRU (ORCPT ); Fri, 9 May 2008 23:17:20 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756748AbYEJDKU (ORCPT ); Fri, 9 May 2008 23:10:20 -0400 Received: from netops-testserver-3-out.sgi.com ([192.48.171.28]:55072 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753381AbYEJDJX (ORCPT ); Fri, 9 May 2008 23:09:23 -0400 Message-Id: <20080510030919.121690414@sgi.com> References: <20080510030831.796641881@sgi.com> User-Agent: quilt/0.46-1 Date: Fri, 09 May 2008 20:08:50 -0700 From: Christoph Lameter To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Alexander Viro , Christoph Hellwig CC: linux-fsdevel@vger.kernel.org Cc: Mel Gorman Cc: andi@firstfloor.org Cc: Rik van Riel Cc: Pekka Enberg Cc: mpm@selenic.com Subject: [patch 19/21] dentries: Add constructor Content-Disposition: inline; filename=0031-dentries-Add-constructor.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to support defragmentation on the dentry cache we need to have a determined object state at all times. Without a constructor the object would have a random state after allocation. So provide a constructor. Cc: Alexander Viro Cc: Christoph Hellwig Reviewed-by: Rik van Riel Signed-off-by: Christoph Lameter --- fs/dcache.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) Index: linux-2.6/fs/dcache.c =================================================================== --- linux-2.6.orig/fs/dcache.c 2008-05-07 19:59:03.441408469 -0700 +++ linux-2.6/fs/dcache.c 2008-05-07 21:22:07.891408627 -0700 @@ -870,6 +870,16 @@ static struct shrinker dcache_shrinker = .seeks = DEFAULT_SEEKS, }; +static void dcache_ctor(struct kmem_cache *s, void *p) +{ + struct dentry *dentry = p; + + spin_lock_init(&dentry->d_lock); + dentry->d_inode = NULL; + INIT_LIST_HEAD(&dentry->d_lru); + INIT_LIST_HEAD(&dentry->d_alias); +} + /** * d_alloc - allocate a dcache entry * @parent: parent of entry to allocate @@ -907,8 +917,6 @@ struct dentry *d_alloc(struct dentry * p atomic_set(&dentry->d_count, 1); dentry->d_flags = DCACHE_UNHASHED; - spin_lock_init(&dentry->d_lock); - dentry->d_inode = NULL; dentry->d_parent = NULL; dentry->d_sb = NULL; dentry->d_op = NULL; @@ -918,9 +926,7 @@ struct dentry *d_alloc(struct dentry * p dentry->d_cookie = NULL; #endif INIT_HLIST_NODE(&dentry->d_hash); - INIT_LIST_HEAD(&dentry->d_lru); INIT_LIST_HEAD(&dentry->d_subdirs); - INIT_LIST_HEAD(&dentry->d_alias); if (parent) { dentry->d_parent = dget(parent); @@ -2148,14 +2154,10 @@ static void __init dcache_init(void) { int loop; - /* - * A constructor could be added for stable state like the lists, - * but it is probably not worth it because of the cache nature - * of the dcache. - */ - dentry_cache = KMEM_CACHE(dentry, - SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD); - + dentry_cache = kmem_cache_create("dentry_cache", sizeof(struct dentry), + 0, SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD, + dcache_ctor); + register_shrinker(&dcache_shrinker); /* Hash may have been set up in dcache_init_early */ --