fs/super.c: defer more work after super_block is off of the super_blocks list
PATCH 1/1 fs/super.c: defer more work after super_block is off of the super_blocks list
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.
--- fs/super.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
fs/super.c +13 -5
@@ -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);
Signature · 1 line
2.30.2
Quoted 10 lines · Luis Chamberlain
Once it is off the
super_blockslist we don't really need to hold thesb_lockanymore, we can defer the rest of the work. This reduces a few uneeded operations from contention from thesb_lock.This is a minor optimization found through code inspection. If the
sb_lockis 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 thesb_lockis used.Signed-off-by Luis Chamberlain <[email protected]>
*poke*
Luis