linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Imran Khan <imran.f.khan@oracle.com>
To: tj@kernel.org, viro@zeniv.linux.org.uk,
	gregkh@linuxfoundation.org, ebiederm@xmission.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH v8 06/10] kernfs: Use a per-fs rwsem to protect per-fs list of kernfs_super_info.
Date: Sun, 10 Apr 2022 12:37:15 +1000	[thread overview]
Message-ID: <20220410023719.1752460-7-imran.f.khan@oracle.com> (raw)
In-Reply-To: <20220410023719.1752460-1-imran.f.khan@oracle.com>

Right now per-fs kernfs_rwsem protects list of kernfs_super_info instances
for a kernfs_root. Since kernfs_rwsem is used to synchronize several other
operations across kernfs and since most of these operations don't impact
kernfs_super_info, we can use a separate per-fs rwsem to synchronize access
to list of kernfs_super_info.
This helps in reducing contention around kernfs_rwsem and also allows
operations that change/access list of kernfs_super_info to proceed without
contending for kernfs_rwsem.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
---
 fs/kernfs/dir.c             | 1 +
 fs/kernfs/file.c            | 2 ++
 fs/kernfs/kernfs-internal.h | 1 +
 fs/kernfs/mount.c           | 8 ++++----
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 61a8edc4ba8b..17b438498c0b 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -917,6 +917,7 @@ struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
 	idr_init(&root->ino_idr);
 	init_rwsem(&root->kernfs_rwsem);
 	INIT_LIST_HEAD(&root->supers);
+	init_rwsem(&root->supers_rwsem);
 
 	/*
 	 * On 64bit ino setups, id is ino.  On 32bit, low 32bits are ino.
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index 0946ab341ce4..0bffe5d0f510 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -890,6 +890,7 @@ static void kernfs_notify_workfn(struct work_struct *work)
 	/* kick fsnotify */
 	down_write(&root->kernfs_rwsem);
 
+	down_write(&root->supers_rwsem);
 	list_for_each_entry(info, &kernfs_root(kn)->supers, node) {
 		struct kernfs_node *parent;
 		struct inode *p_inode = NULL;
@@ -925,6 +926,7 @@ static void kernfs_notify_workfn(struct work_struct *work)
 
 		iput(inode);
 	}
+	up_write(&root->supers_rwsem);
 
 	up_write(&root->kernfs_rwsem);
 	kernfs_put(kn);
diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h
index eeaa779b929c..82c6b16645bc 100644
--- a/fs/kernfs/kernfs-internal.h
+++ b/fs/kernfs/kernfs-internal.h
@@ -47,6 +47,7 @@ struct kernfs_root {
 
 	wait_queue_head_t	deactivate_waitq;
 	struct rw_semaphore	kernfs_rwsem;
+	struct rw_semaphore     supers_rwsem;
 };
 
 /* +1 to avoid triggering overflow warning when negating it */
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index a64a04efc9be..1ac36b2a89ab 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -347,9 +347,9 @@ int kernfs_get_tree(struct fs_context *fc)
 		}
 		sb->s_flags |= SB_ACTIVE;
 
-		down_write(&root->kernfs_rwsem);
+		down_write(&root->supers_rwsem);
 		list_add(&info->node, &info->root->supers);
-		up_write(&root->kernfs_rwsem);
+		up_write(&root->supers_rwsem);
 	}
 
 	fc->root = dget(sb->s_root);
@@ -376,9 +376,9 @@ void kernfs_kill_sb(struct super_block *sb)
 	struct kernfs_super_info *info = kernfs_info(sb);
 	struct kernfs_root *root = info->root;
 
-	down_write(&root->kernfs_rwsem);
+	down_write(&root->supers_rwsem);
 	list_del(&info->node);
-	up_write(&root->kernfs_rwsem);
+	up_write(&root->supers_rwsem);
 
 	/*
 	 * Remove the superblock from fs_supers/s_instances
-- 
2.30.2


  parent reply	other threads:[~2022-04-10  2:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-10  2:37 [PATCH v8 00/10] kernfs: Remove reference counting for kernfs_open_node Imran Khan
2022-04-10  2:37 ` [PATCH v8 01/10] " Imran Khan
2022-04-22 16:03   ` Tejun Heo
2022-04-26  1:43     ` Imran Khan
2022-04-26 18:29       ` Tejun Heo
2022-04-26 20:13         ` Al Viro
2022-04-26 20:16           ` Tejun Heo
2022-04-10  2:37 ` [PATCH v8 02/10] kernfs: make ->attr.open RCU protected Imran Khan
2022-04-22 16:19   ` Tejun Heo
2022-04-26  1:54     ` Imran Khan
2022-04-26 18:37       ` Tejun Heo
2022-04-10  2:37 ` [PATCH v8 03/10] kernfs: Change kernfs_notify_list to llist Imran Khan
2022-04-22 16:41   ` Tejun Heo
2022-04-10  2:37 ` [PATCH v8 04/10] kernfs: Introduce interface to access global kernfs_open_file_mutex Imran Khan
2022-04-10  2:37 ` [PATCH v8 05/10] kernfs: Replace global kernfs_open_file_mutex with hashed mutexes Imran Khan
2022-04-22 17:00   ` Tejun Heo
2022-04-10  2:37 ` Imran Khan [this message]
2022-04-10  2:37 ` [PATCH v8 07/10] kernfs: Change kernfs_rename_lock into a read-write lock Imran Khan
2022-04-10  2:37 ` [PATCH v8 08/10] kernfs: Introduce interface to access per-fs rwsem Imran Khan
2022-04-10  2:37 ` [PATCH v8 09/10] kernfs: Replace per-fs rwsem with hashed rwsems Imran Khan
2022-04-10  2:37 ` [PATCH v8 10/10] kernfs: Add a document to describe hashed locks used in kernfs Imran Khan
2022-04-22 17:03 ` [PATCH v8 00/10] kernfs: Remove reference counting for kernfs_open_node Tejun Heo
2022-04-23  8:49   ` Imran Khan
2022-04-25 17:21     ` Tejun Heo
2022-04-28 17:28       ` Imran Khan

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=20220410023719.1752460-7-imran.f.khan@oracle.com \
    --to=imran.f.khan@oracle.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).