mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: viro@zeniv.linux.org.uk
Cc: neilb@suse.de, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH] fs/super.c: defer more work after super_block is off of the super_blocks list
Date: Fri, 22 Oct 2021 16:28:46 -0700	[thread overview]
Message-ID: <20211022232846.2890326-1-mcgrof@kernel.org> (raw)

Once it is off the super_blocks list we don't really need to hold the
sb_lock anymore, we can defer the rest of the work. This reduces a few
uneeded operations from contention from the sb_lock.

This is a minor optimization found through code inspection. If the
sb_lock is not needed, no need for contention to wait while we free
items. While at it, add a bit of documentation about the extent to
which the sb_lock is used.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 fs/super.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index bcef3a6f4c4b..24a76490c46f 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -43,6 +43,13 @@
 static int thaw_super_locked(struct super_block *sb);
 
 static LIST_HEAD(super_blocks);
+
+/**
+ * Protects the super_blocks list as well as the respective fs_type->fs_supers.
+ * When removing a super block it is first removed from the fs_type->fs_supers
+ * through generic_shutdown_super(). The final nail on the super block is the
+ * last temporary reference with __put_super().
+ */
 static DEFINE_SPINLOCK(sb_lock);
 
 static char *sb_writers_name[SB_FREEZE_LEVELS] = {
@@ -160,6 +167,11 @@ static void destroy_super_work(struct work_struct *work)
 							destroy_work);
 	int i;
 
+	security_sb_free(s);
+	fscrypt_sb_free(s);
+	put_user_ns(s->s_user_ns);
+	kfree(s->s_subtype);
+
 	for (i = 0; i < SB_FREEZE_LEVELS; i++)
 		percpu_free_rwsem(&s->s_writers.rw_sem[i]);
 	kfree(s);
@@ -292,10 +304,6 @@ static void __put_super(struct super_block *s)
 		WARN_ON(s->s_dentry_lru.node);
 		WARN_ON(s->s_inode_lru.node);
 		WARN_ON(!list_empty(&s->s_mounts));
-		security_sb_free(s);
-		fscrypt_sb_free(s);
-		put_user_ns(s->s_user_ns);
-		kfree(s->s_subtype);
 		call_rcu(&s->rcu, destroy_super_rcu);
 	}
 }
@@ -471,7 +479,7 @@ void generic_shutdown_super(struct super_block *sb)
 		}
 	}
 	spin_lock(&sb_lock);
-	/* should be initialized for __put_super_and_need_restart() */
+	/* and so __put_super() does not need to deal with this */
 	hlist_del_init(&sb->s_instances);
 	spin_unlock(&sb_lock);
 	up_write(&sb->s_umount);
-- 
2.30.2


             reply	other threads:[~2021-10-22 23:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 23:28 Luis Chamberlain [this message]
2021-11-03 12:14 ` Luis Chamberlain

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=20211022232846.2890326-1-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --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

all inboxes | Powered by JetHome®