[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <162077996909.14498.13723739782307701863.stgit@web.messagingengine.com>
Date: Wed, 12 May 2021 08:39:29 +0800
From: Ian Kent <raven@...maw.net>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Tejun Heo <tj@...nel.org>
Cc: Al Viro <viro@...IV.linux.org.uk>,
Eric Sandeen <sandeen@...deen.net>,
Fox Chen <foxhlchen@...il.com>,
Brice Goglin <brice.goglin@...il.com>,
Rick Lindsley <ricklind@...ux.vnet.ibm.com>,
David Howells <dhowells@...hat.com>,
Miklos Szeredi <miklos@...redi.hu>,
Marcelo Tosatti <mtosatti@...hat.com>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: [PATCH v4 5/5] kernfs: add kernfs_need_inode_refresh()
Now the kernfs_rwsem read lock is held for kernfs_refresh_inode() and
the i_lock taken to protect inode updates there can be some contention
introduced when .permission() is called with concurrent path walks in
progress.
Since .permission() is called frequently during path walks it's worth
checking if the update is actually needed before taking the lock and
performing the update.
Signed-off-by: Ian Kent <raven@...maw.net>
---
fs/kernfs/inode.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 6728ecd81eb37..67fb1289c51dc 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -158,6 +158,30 @@ static inline void set_default_inode_attr(struct inode *inode, umode_t mode)
inode->i_ctime = current_time(inode);
}
+static bool kernfs_need_inode_refresh(struct kernfs_node *kn,
+ struct inode *inode,
+ struct kernfs_iattrs *attrs)
+{
+ if (kernfs_type(kn) == KERNFS_DIR) {
+ if (inode->i_nlink != kn->dir.subdirs + 2)
+ return true;
+ }
+
+ if (inode->i_mode != kn->mode)
+ return true;
+
+ if (attrs) {
+ if (!timespec64_equal(&inode->i_atime, &attrs->ia_atime) ||
+ !timespec64_equal(&inode->i_mtime, &attrs->ia_mtime) ||
+ !timespec64_equal(&inode->i_ctime, &attrs->ia_ctime) ||
+ !uid_eq(inode->i_uid, attrs->ia_uid) ||
+ !gid_eq(inode->i_gid, attrs->ia_gid))
+ return true;
+ }
+
+ return false;
+}
+
static inline void set_inode_attr(struct inode *inode,
struct kernfs_iattrs *attrs)
{
@@ -172,6 +196,9 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
{
struct kernfs_iattrs *attrs = kn->iattr;
+ if (!kernfs_need_inode_refresh(kn, inode, attrs))
+ return;
+
spin_lock(&inode->i_lock);
inode->i_mode = kn->mode;
if (attrs)
Powered by blists - more mailing lists