Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753378Ab0K0K1H (ORCPT ); Sat, 27 Nov 2010 05:27:07 -0500 Received: from ipmail04.adl6.internode.on.net ([150.101.137.141]:6979 "EHLO ipmail04.adl6.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753323Ab0K0K1E (ORCPT ); Sat, 27 Nov 2010 05:27:04 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApcFAO1p8Ex5Lcx2/2dsb2JhbACVC44Acr12hUcEimGFFA Message-Id: <219638b14eed01855f638628fd5d9d967d033a5b.1290852959.git.npiggin@kernel.dk> In-Reply-To: References: From: Nick Piggin Date: Sat, 27 Nov 2010 20:44:55 +1100 Subject: [PATCH 25/46] fs: dcache reduce d_parent locking To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1379 Lines: 58 Use RCU to simplify locking in dget_parent. Signed-off-by: Nick Piggin --- fs/dcache.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 9231748..23f6fed 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -406,24 +406,27 @@ struct dentry *dget_parent(struct dentry *dentry) struct dentry *ret; repeat: - spin_lock(&dentry->d_lock); + /* + * Don't need rcu_dereference because we re-check it was correct under + * the lock. + */ + rcu_read_lock(); ret = dentry->d_parent; - if (!ret) - goto out; - if (dentry == ret) { - ret->d_count++; - goto out; - } - if (!spin_trylock(&ret->d_lock)) { - spin_unlock(&dentry->d_lock); - cpu_relax(); + if (!ret) { + rcu_read_unlock(); + goto out; + } + spin_lock(&ret->d_lock); + if (unlikely(ret != dentry->d_parent)) { + spin_unlock(&ret->d_lock); + rcu_read_unlock(); goto repeat; } + rcu_read_unlock(); BUG_ON(!ret->d_count); ret->d_count++; spin_unlock(&ret->d_lock); out: - spin_unlock(&dentry->d_lock); return ret; } EXPORT_SYMBOL(dget_parent); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/