From: NeilBrown <neilb@suse.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] Improve fairness when locking the per-superblock s_anon list
Date: Thu, 09 Nov 2017 14:22:07 +1100 [thread overview]
Message-ID: <151019772760.30101.8513274540570798315.stgit@noble> (raw)
In-Reply-To: <151019756744.30101.3832608128627682973.stgit@noble>
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 per-sb (fair) spinlock and take it before grabing the
bitlock on s_anon. This provides fairness and makes the warnings go away.
Signed-off-by: NeilBrown <neilb@suse.com>
---
fs/dcache.c | 11 ++++++++++-
fs/super.c | 1 +
include/linux/fs.h | 1 +
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index f90141387f01..d5952306206b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -51,6 +51,8 @@
* - the dcache hash table
* s_anon bl list spinlock protects:
* - the s_anon list (see __d_drop)
+ * dentry->d_sb->s_anon_lock protect:
+ * - the s_anon bl bitlock, ensuring fairness.
* dentry->d_sb->s_dentry_lru_lock protects:
* - the dcache lru lists and counters
* d_lock protects:
@@ -484,7 +486,12 @@ void __d_drop(struct dentry *dentry)
else
b = d_hash(dentry->d_name.hash);
- hlist_bl_lock(b);
+ if (b == &dentry->d_sb->s_anon) {
+ spin_lock(&dentry->d_sb->s_anon_lock);
+ hlist_bl_lock(b);
+ spin_unlock(&dentry->d_sb->s_anon_lock);
+ } else
+ hlist_bl_lock(b);
__hlist_bl_del(&dentry->d_hash);
dentry->d_hash.pprev = NULL;
hlist_bl_unlock(b);
@@ -1965,7 +1972,9 @@ 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(&tmp->d_sb->s_anon_lock);
hlist_bl_lock(&tmp->d_sb->s_anon);
+ spin_unlock(&tmp->d_sb->s_anon_lock);
hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_anon);
hlist_bl_unlock(&tmp->d_sb->s_anon);
spin_unlock(&tmp->d_lock);
diff --git a/fs/super.c b/fs/super.c
index 994db21f59bf..af644ae93445 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -209,6 +209,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags,
if (s->s_user_ns != &init_user_ns)
s->s_iflags |= SB_I_NODEV;
INIT_HLIST_NODE(&s->s_instances);
+ spin_lock_init(&s->s_anon_lock);
INIT_HLIST_BL_HEAD(&s->s_anon);
mutex_init(&s->s_sync_lock);
INIT_LIST_HEAD(&s->s_inodes);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 885266aae2d7..9df9bace53fb 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1359,6 +1359,7 @@ struct super_block {
const struct fscrypt_operations *s_cop;
+ spinlock_t s_anon_lock; /* needed for fairness */
struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */
struct list_head s_mounts; /* list of mounts; _not_ for fs use */
struct block_device *s_bdev;
next prev parent reply other threads:[~2017-11-09 3:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-09 3:22 [PATCH 0/3] Three VFS patch resends NeilBrown
2017-11-09 3:22 ` [PATCH 1/3] VFS: use synchronize_rcu_expedited() in namespace_unlock() NeilBrown
2017-11-09 3:22 ` [PATCH 3/3] VFS: close race between getcwd() and d_move() NeilBrown
2017-11-09 11:41 ` Nikolay Borisov
2017-11-09 13:08 ` Matthew Wilcox
2017-11-09 16:02 ` Nikolay Borisov
2017-11-09 20:23 ` Linus Torvalds
2017-11-09 22:14 ` NeilBrown
2017-11-10 1:40 ` Linus Torvalds
2017-11-10 4:45 ` NeilBrown
2017-11-10 19:52 ` Linus Torvalds
2017-11-10 20:53 ` Al Viro
2017-11-21 23:50 ` Al Viro
2017-11-22 1:31 ` NeilBrown
2017-11-09 3:22 ` NeilBrown [this message]
2017-11-09 19:52 ` [PATCH 2/3] Improve fairness when locking the per-superblock s_anon list Linus Torvalds
2017-11-09 20:50 ` Al Viro
2017-11-09 23:09 ` NeilBrown
2017-11-09 23:19 ` Al Viro
2017-11-10 0:02 ` Linus Torvalds
2017-11-10 8:50 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=151019772760.30101.8513274540570798315.stgit@noble \
--to=neilb@suse.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.