Author: mjg
Date: Mon Apr 23 07:54:02 2018
New Revision: 332881
URL: https://svnweb.freebsd.org/changeset/base/332881

Log:
  lockf: skip locking the graph if not necessary (common case)
  
  Tested by:      pho

Modified:
  head/sys/kern/kern_lockf.c

Modified: head/sys/kern/kern_lockf.c
==============================================================================
--- head/sys/kern/kern_lockf.c  Mon Apr 23 07:52:56 2018        (r332880)
+++ head/sys/kern/kern_lockf.c  Mon Apr 23 07:54:02 2018        (r332881)
@@ -1053,6 +1053,12 @@ lf_add_incoming(struct lockf *state, struct lockf_entr
        struct lockf_entry *overlap;
        int error;
 
+       sx_assert(&state->ls_lock, SX_XLOCKED);
+       if (LIST_EMPTY(&state->ls_pending))
+               return (0);
+
+       error = 0;
+       sx_xlock(&lf_owner_graph_lock);
        LIST_FOREACH(overlap, &state->ls_pending, lf_link) {
                if (!lf_blocks(lock, overlap))
                        continue;
@@ -1070,10 +1076,11 @@ lf_add_incoming(struct lockf *state, struct lockf_entr
                 */
                if (error) {
                        lf_remove_incoming(lock);
-                       return (error);
+                       break;
                }
        }
-       return (0);
+       sx_xunlock(&lf_owner_graph_lock);
+       return (error);
 }
 
 /*
@@ -1509,9 +1516,7 @@ lf_setlock(struct lockf *state, struct lockf_entry *lo
         * edges from any currently pending lock that the new lock
         * would block.
         */
-       sx_xlock(&lf_owner_graph_lock);
        error = lf_add_incoming(state, lock);
-       sx_xunlock(&lf_owner_graph_lock);
        if (error) {
 #ifdef LOCKF_DEBUG
                if (lockf_debug & 1)
@@ -1840,9 +1845,7 @@ lf_split(struct lockf *state, struct lockf_entry *lock
        splitlock->lf_start = lock2->lf_end + 1;
        LIST_INIT(&splitlock->lf_outedges);
        LIST_INIT(&splitlock->lf_inedges);
-       sx_xlock(&lf_owner_graph_lock);
        lf_add_incoming(state, splitlock);
-       sx_xunlock(&lf_owner_graph_lock);
 
        lf_set_end(state, lock1, lock2->lf_start - 1, granted);
 
_______________________________________________
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