From patchwork Fri Jan 29 00:17:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 8155201 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DE47D9F38B for ; Fri, 29 Jan 2016 00:17:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E65920364 for ; Fri, 29 Jan 2016 00:17:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B10F20361 for ; Fri, 29 Jan 2016 00:17:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751196AbcA2ARx (ORCPT ); Thu, 28 Jan 2016 19:17:53 -0500 Received: from mx2.suse.de ([195.135.220.15]:43991 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751193AbcA2ARx (ORCPT ); Thu, 28 Jan 2016 19:17:53 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 84531AC2E; Fri, 29 Jan 2016 00:17:51 +0000 (UTC) From: NeilBrown To: Al Viro , Dave Chinner Date: Fri, 29 Jan 2016 11:17:43 +1100 Cc: LKML , linux-nfs@vger.kernel.org Subject: [PATCH/RFC] VFS: Improve fairness when locking the per-superblock s_anon list User-Agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-suse-linux-gnu) Message-ID: <87fuxh1bo8.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bit-spin-locks, as used for dcache hash chains, are not fair. This is not a problem for the dcache hash table as different CPUs are likely to access different entries in the hash table so high contention is not expected. However anonymous dentryies (created by NFSD) all live on a single hash chain "s_anon" and the bitlock on this can be highly contended, resulting in soft-lockup warnings. So introduce a global (fair) spinlock and take it before grabing the bitlock on s_anon. This provides fairness and makes the warnings go away. We could alternately use s_inode_list_lock, or add another spinlock to struct super_block. Suggestions? Signed-off-by: NeilBrown --- Dave: I'd guess you would be against using the new s_inode_list_lock for this because it is already highly contended - yes? Is it worth adding another spinlock to 'struct super_block' ? Thanks, NeilBrown fs/dcache.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 92d5140de851..e83f1ac1540c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -104,6 +104,8 @@ static unsigned int d_hash_shift __read_mostly; static struct hlist_bl_head *dentry_hashtable __read_mostly; +static DEFINE_SPINLOCK(s_anon_lock); + static inline struct hlist_bl_head *d_hash(const struct dentry *parent, unsigned int hash) { @@ -490,10 +492,14 @@ void __d_drop(struct dentry *dentry) else b = d_hash(dentry->d_parent, dentry->d_name.hash); + if (b == &dentry->d_sb->s_anon) + spin_lock(&s_anon_lock); hlist_bl_lock(b); __hlist_bl_del(&dentry->d_hash); dentry->d_hash.pprev = NULL; hlist_bl_unlock(b); + if (b == &dentry->d_sb->s_anon) + spin_unlock(&s_anon_lock); dentry_rcuwalk_invalidate(dentry); } } @@ -1978,9 +1984,11 @@ static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected) spin_lock(&tmp->d_lock); __d_set_inode_and_type(tmp, inode, add_flags); hlist_add_head(&tmp->d_u.d_alias, &inode->i_dentry); + spin_lock(&s_anon_lock); hlist_bl_lock(&tmp->d_sb->s_anon); hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_anon); hlist_bl_unlock(&tmp->d_sb->s_anon); + spin_unlock(&s_anon_lock); spin_unlock(&tmp->d_lock); spin_unlock(&inode->i_lock); security_d_instantiate(tmp, inode);