Author: kib
Date: Sun Oct  6 06:09:43 2013
New Revision: 256077
URL: http://svnweb.freebsd.org/changeset/base/256077

Log:
  MFC r255941:
  Increase the chance of the buffer write from the bufdaemon helper
  context to succeed. If the locked vnode which owns the buffer to be
  written is shared locked, try the non-blocking upgrade of the lock to
  exclusive.

Modified:
  stable/9/sys/kern/vfs_bio.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/vfs_bio.c
==============================================================================
--- stable/9/sys/kern/vfs_bio.c Sun Oct  6 06:05:11 2013        (r256076)
+++ stable/9/sys/kern/vfs_bio.c Sun Oct  6 06:09:43 2013        (r256077)
@@ -2671,6 +2671,8 @@ flushbufqueues(struct vnode *lvp, int qu
        int hasdeps;
        int flushed;
        int target;
+       int error;
+       bool unlock;
 
        if (lvp == NULL) {
                target = numdirtybuffers - lodirtybuffers;
@@ -2751,7 +2753,16 @@ flushbufqueues(struct vnode *lvp, int qu
                        BUF_UNLOCK(bp);
                        continue;
                }
-               if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_CANRECURSE) == 0) 
{
+               if (lvp == NULL) {
+                       unlock = true;
+                       error = vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT);
+               } else {
+                       ASSERT_VOP_LOCKED(vp, "getbuf");
+                       unlock = false;
+                       error = VOP_ISLOCKED(vp) == LK_EXCLUSIVE ? 0 :
+                           vn_lock(vp, LK_TRYUPGRADE);
+               }
+               if (error == 0) {
                        mtx_unlock(&bqlock);
                        CTR3(KTR_BUF, "flushbufqueue(%p) vp %p flags %X",
                            bp, bp->b_vp, bp->b_flags);
@@ -2763,7 +2774,8 @@ flushbufqueues(struct vnode *lvp, int qu
                                notbufdflashes++;
                        }
                        vn_finished_write(mp);
-                       VOP_UNLOCK(vp, 0);
+                       if (unlock)
+                               VOP_UNLOCK(vp, 0);
                        flushwithdeps += hasdeps;
                        flushed++;
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "[email protected]"

Reply via email to