Author: mjg
Date: Mon Aug 10 10:36:43 2020
New Revision: 364069
URL: https://svnweb.freebsd.org/changeset/base/364069

Log:
  devfs: save on spurious relocking for devfs_populate
  
  Tested by:    pho

Modified:
  head/sys/fs/devfs/devfs.h
  head/sys/fs/devfs/devfs_devs.c
  head/sys/fs/devfs/devfs_vnops.c

Modified: head/sys/fs/devfs/devfs.h
==============================================================================
--- head/sys/fs/devfs/devfs.h   Mon Aug 10 10:36:10 2020        (r364068)
+++ head/sys/fs/devfs/devfs.h   Mon Aug 10 10:36:43 2020        (r364069)
@@ -192,6 +192,7 @@ char        *devfs_fqpn(char *, struct devfs_mount *, 
struct 
            struct componentname *);
 void   devfs_delete(struct devfs_mount *, struct devfs_dirent *, int);
 void   devfs_dirent_free(struct devfs_dirent *);
+bool   devfs_populate_needed(struct devfs_mount *dm);
 void   devfs_populate(struct devfs_mount *);
 void   devfs_cleanup(struct devfs_mount *);
 void   devfs_unmount_final(struct devfs_mount *);

Modified: head/sys/fs/devfs/devfs_devs.c
==============================================================================
--- head/sys/fs/devfs/devfs_devs.c      Mon Aug 10 10:36:10 2020        
(r364068)
+++ head/sys/fs/devfs/devfs_devs.c      Mon Aug 10 10:36:43 2020        
(r364069)
@@ -659,6 +659,13 @@ devfs_populate_loop(struct devfs_mount *dm, int cleanu
        return (0);
 }
 
+bool
+devfs_populate_needed(struct devfs_mount *dm)
+{
+
+       return (dm->dm_generation != devfs_generation);
+}
+
 /*
  * The caller needs to hold the dm for the duration of the call.
  */
@@ -668,9 +675,9 @@ devfs_populate(struct devfs_mount *dm)
        unsigned gen;
 
        sx_assert(&dm->dm_lock, SX_XLOCKED);
-       gen = devfs_generation;
-       if (dm->dm_generation == gen)
+       if (!devfs_populate_needed(dm))
                return;
+       gen = devfs_generation;
        while (devfs_populate_loop(dm, 0))
                continue;
        dm->dm_generation = gen;

Modified: head/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- head/sys/fs/devfs/devfs_vnops.c     Mon Aug 10 10:36:10 2020        
(r364068)
+++ head/sys/fs/devfs/devfs_vnops.c     Mon Aug 10 10:36:43 2020        
(r364069)
@@ -235,6 +235,11 @@ devfs_populate_vp(struct vnode *vp)
        ASSERT_VOP_LOCKED(vp, "devfs_populate_vp");
 
        dmp = VFSTODEVFS(vp->v_mount);
+       if (!devfs_populate_needed(dmp)) {
+               sx_xlock(&dmp->dm_lock);
+               goto out_nopopulate;
+       }
+
        locked = VOP_ISLOCKED(vp);
 
        sx_xlock(&dmp->dm_lock);
@@ -252,6 +257,7 @@ devfs_populate_vp(struct vnode *vp)
                devfs_unmount_final(dmp);
                return (ERESTART);
        }
+out_nopopulate:
        if (VN_IS_DOOMED(vp)) {
                sx_xunlock(&dmp->dm_lock);
                return (ERESTART);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to