Author: avg
Date: Tue Nov 26 20:09:43 2013
New Revision: 258665
URL: http://svnweb.freebsd.org/changeset/base/258665

Log:
  4347 ZPL can use dmu_tx_assign(TXG_WAIT)
  
  illumos/illumos-gate@e722410c49fe67cbf0f639cbcc288bd6cbcf7dd1

Modified:
  vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_vnops.c
  vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_znode.c

Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c Tue Nov 26 20:03:25 
2013        (r258664)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_dir.c Tue Nov 26 20:09:43 
2013        (r258665)
@@ -937,7 +937,6 @@ zfs_make_xattrdir(znode_t *zp, vattr_t *
                return (SET_ERROR(EDQUOT));
        }
 
-top:
        tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
            ZFS_SA_BASE_ATTR_SIZE);
@@ -946,13 +945,8 @@ top:
        fuid_dirtied = zfsvfs->z_fuid_dirty;
        if (fuid_dirtied)
                zfs_fuid_txhold(zfsvfs, tx);
-       error = dmu_tx_assign(tx, TXG_NOWAIT);
+       error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
-               if (error == ERESTART) {
-                       dmu_tx_wait(tx);
-                       dmu_tx_abort(tx);
-                       goto top;
-               }
                zfs_acl_ids_free(&acl_ids);
                dmu_tx_abort(tx);
                return (error);

Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_vnops.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_vnops.c       Tue Nov 26 
20:03:25 2013        (r258664)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_vnops.c       Tue Nov 26 
20:09:43 2013        (r258665)
@@ -111,11 +111,18 @@
  *  (3)        All range locks must be grabbed before calling dmu_tx_assign(),
  *     as they can span dmu_tx_assign() calls.
  *
- *  (4)        Always pass TXG_NOWAIT as the second argument to 
dmu_tx_assign().
- *     This is critical because we don't want to block while holding locks.
- *     Note, in particular, that if a lock is sometimes acquired before
- *     the tx assigns, and sometimes after (e.g. z_lock), then failing to
- *     use a non-blocking assign can deadlock the system.  The scenario:
+ *  (4) If ZPL locks are held, pass TXG_NOWAIT as the second argument to
+ *      dmu_tx_assign().  This is critical because we don't want to block
+ *      while holding locks.
+ *
+ *     If no ZPL locks are held (aside from ZFS_ENTER()), use TXG_WAIT.  This
+ *     reduces lock contention and CPU usage when we must wait (note that if
+ *     throughput is constrained by the storage, nearly every transaction
+ *     must wait).
+ *
+ *      Note, in particular, that if a lock is sometimes acquired before
+ *      the tx assigns, and sometimes after (e.g. z_lock), then failing
+ *      to use a non-blocking assign can deadlock the system.  The scenario:
  *
  *     Thread A has grabbed a lock before calling dmu_tx_assign().
  *     Thread B is in an already-assigned tx, and blocks for this lock.
@@ -728,7 +735,6 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
        while (n > 0) {
                abuf = NULL;
                woff = uio->uio_loffset;
-again:
                if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
                    zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
                        if (abuf != NULL)
@@ -780,13 +786,8 @@ again:
                dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
                dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
                zfs_sa_upgrade_txholds(tx, zp);
-               error = dmu_tx_assign(tx, TXG_NOWAIT);
+               error = dmu_tx_assign(tx, TXG_WAIT);
                if (error) {
-                       if (error == ERESTART) {
-                               dmu_tx_wait(tx);
-                               dmu_tx_abort(tx);
-                               goto again;
-                       }
                        dmu_tx_abort(tx);
                        if (abuf != NULL)
                                dmu_return_arcbuf(abuf);
@@ -3043,12 +3044,9 @@ top:
 
        zfs_sa_upgrade_txholds(tx, zp);
 
-       err = dmu_tx_assign(tx, TXG_NOWAIT);
-       if (err) {
-               if (err == ERESTART)
-                       dmu_tx_wait(tx);
+       err = dmu_tx_assign(tx, TXG_WAIT);
+       if (err)
                goto out;
-       }
 
        count = 0;
        /*
@@ -4140,19 +4138,13 @@ zfs_putapage(vnode_t *vp, page_t *pp, u_
                err = SET_ERROR(EDQUOT);
                goto out;
        }
-top:
        tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_write(tx, zp->z_id, off, len);
 
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
-       err = dmu_tx_assign(tx, TXG_NOWAIT);
+       err = dmu_tx_assign(tx, TXG_WAIT);
        if (err != 0) {
-               if (err == ERESTART) {
-                       dmu_tx_wait(tx);
-                       dmu_tx_abort(tx);
-                       goto top;
-               }
                dmu_tx_abort(tx);
                goto out;
        }

Modified: vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_znode.c
==============================================================================
--- vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_znode.c       Tue Nov 26 
20:03:25 2013        (r258664)
+++ vendor-sys/illumos/dist/uts/common/fs/zfs/zfs_znode.c       Tue Nov 26 
20:09:43 2013        (r258665)
@@ -1469,7 +1469,6 @@ zfs_extend(znode_t *zp, uint64_t end)
                zfs_range_unlock(rl);
                return (0);
        }
-top:
        tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
@@ -1489,13 +1488,8 @@ top:
                newblksz = 0;
        }
 
-       error = dmu_tx_assign(tx, TXG_NOWAIT);
+       error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
-               if (error == ERESTART) {
-                       dmu_tx_wait(tx);
-                       dmu_tx_abort(tx);
-                       goto top;
-               }
                dmu_tx_abort(tx);
                zfs_range_unlock(rl);
                return (error);
@@ -1592,17 +1586,11 @@ zfs_trunc(znode_t *zp, uint64_t end)
                zfs_range_unlock(rl);
                return (error);
        }
-top:
        tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
-       error = dmu_tx_assign(tx, TXG_NOWAIT);
+       error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
-               if (error == ERESTART) {
-                       dmu_tx_wait(tx);
-                       dmu_tx_abort(tx);
-                       goto top;
-               }
                dmu_tx_abort(tx);
                zfs_range_unlock(rl);
                return (error);
@@ -1709,13 +1697,8 @@ log:
        tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
-       error = dmu_tx_assign(tx, TXG_NOWAIT);
+       error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
-               if (error == ERESTART) {
-                       dmu_tx_wait(tx);
-                       dmu_tx_abort(tx);
-                       goto log;
-               }
                dmu_tx_abort(tx);
                return (error);
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to