From: Fox Chen <foxhlchen@gmail.com>
To: gregkh@linuxfoundation.org, tj@kernel.org
Cc: Fox Chen <foxhlchen@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] kernfs: replace the mutex in kernfs_iop_permission with a rwlock
Date: Wed, 2 Dec 2020 22:58:36 +0800 [thread overview]
Message-ID: <20201202145837.48040-2-foxhlchen@gmail.com> (raw)
In-Reply-To: <20201202145837.48040-1-foxhlchen@gmail.com>
A big global mutex in kernfs_iop_permission will significanly drag
system performance when processes concurrently open files
on kernfs in Big machines(with >= 16 cpu cores).
This patch replace the big mutex with a rwlock specifically for
protecting kernfs_node->iattribute. So that kernfs_iop_permission
can perform concurrently.
Signed-off-by: Fox Chen <foxhlchen@gmail.com>
---
fs/kernfs/inode.c | 16 ++++++++--------
include/linux/kernfs.h | 1 +
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index fc2469a20fed..c8c2ea669e6d 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -106,9 +106,9 @@ int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
{
int ret;
- mutex_lock(&kernfs_mutex);
+ write_lock(&kn->iattr_rwlock);
ret = __kernfs_setattr(kn, iattr);
- mutex_unlock(&kernfs_mutex);
+ write_unlock(&kn->iattr_rwlock);
return ret;
}
@@ -121,7 +121,7 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)
if (!kn)
return -EINVAL;
- mutex_lock(&kernfs_mutex);
+ write_lock(&kn->iattr_rwlock);
error = setattr_prepare(dentry, iattr);
if (error)
goto out;
@@ -134,7 +134,7 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)
setattr_copy(inode, iattr);
out:
- mutex_unlock(&kernfs_mutex);
+ write_unlock(&kn->iattr_rwlock);
return error;
}
@@ -189,9 +189,9 @@ int kernfs_iop_getattr(const struct path *path, struct kstat *stat,
struct inode *inode = d_inode(path->dentry);
struct kernfs_node *kn = inode->i_private;
- mutex_lock(&kernfs_mutex);
+ read_lock(&kn->iattr_rwlock);
kernfs_refresh_inode(kn, inode);
- mutex_unlock(&kernfs_mutex);
+ read_unlock(&kn->iattr_rwlock);
generic_fillattr(inode, stat);
return 0;
@@ -281,9 +281,9 @@ int kernfs_iop_permission(struct inode *inode, int mask)
kn = inode->i_private;
- mutex_lock(&kernfs_mutex);
+ read_lock(&kn->iattr_rwlock);
kernfs_refresh_inode(kn, inode);
- mutex_unlock(&kernfs_mutex);
+ read_unlock(&kn->iattr_rwlock);
return generic_permission(inode, mask);
}
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 89f6a4214a70..545cdb39b34b 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -156,6 +156,7 @@ struct kernfs_node {
unsigned short flags;
umode_t mode;
struct kernfs_iattrs *iattr;
+ rwlock_t iattr_rwlock;
};
/*
--
2.29.2
next prev parent reply other threads:[~2020-12-02 15:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 14:58 [PATCH 0/2] kernfs: speed up concurrency performance Fox Chen
2020-12-02 14:58 ` Fox Chen [this message]
2020-12-02 18:27 ` [PATCH 1/2] kernfs: replace the mutex in kernfs_iop_permission with a rwlock Greg KH
2020-12-02 18:34 ` Tejun Heo
2020-12-02 18:37 ` Tejun Heo
2020-12-03 6:34 ` Fox Chen
2020-12-03 7:19 ` [kernfs] d680236464: BUG:sleeping_function_called_from_invalid_context_at_kernel/locking/mutex.c kernel test robot
2020-12-02 14:58 ` [PATCH 2/2] kernfs: remove mutex in kernfs_dop_revalidate Fox Chen
2020-12-02 18:27 ` Greg KH
2020-12-03 6:35 ` Fox Chen
2020-12-02 18:46 ` Tejun Heo
2020-12-03 6:44 ` Fox Chen
2020-12-02 18:29 ` [PATCH 0/2] kernfs: speed up concurrency performance Greg KH
2020-12-03 6:38 ` Fox Chen
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=20201202145837.48040-2-foxhlchen@gmail.com \
--to=foxhlchen@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox