Sun Mar 8 19:59:45 2020 UTC ()
Avoid unnecessary zil_commit on rm.

1. Issue zil_commit only if we're actually updating something --
   there's no need to commit if we're unlinking the file or if
   there's no atime update being applied.

2. Issue zil_commit only if the zfs has sync=always set -- for
   sync=standard there's no need for us to commit anything here since
   no application asked for an explicit sync.

Speeds up untarring base.tgz on top of itself by a factor of about
2x, and speeds up rm by a factor of about 10x, on my system with an
SSD SLOG over SATA.  Histogram of unlink, rmdir, and rename timing
shows dramatic reduction in latency for most samples.

(To be fair, this was not an improvement over zfs; issuing the
unnecessary zil_commit was a self-inflicted performance wound.)


(riastradh)
diff -r1.62 -r1.63 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c

cvs diff -r1.62 -r1.63 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c (expand / switch to unified diff)

--- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c 2020/02/23 15:46:38 1.62
+++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c 2020/03/08 19:59:45 1.63
@@ -5848,30 +5848,30 @@ zfs_netbsd_reclaim(void *v) @@ -5848,30 +5848,30 @@ zfs_netbsd_reclaim(void *v)
5848 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os); 5848 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
5849 5849
5850 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE); 5850 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
5851 zfs_sa_upgrade_txholds(tx, zp); 5851 zfs_sa_upgrade_txholds(tx, zp);
5852 error = dmu_tx_assign(tx, TXG_WAIT); 5852 error = dmu_tx_assign(tx, TXG_WAIT);
5853 if (error) { 5853 if (error) {
5854 dmu_tx_abort(tx); 5854 dmu_tx_abort(tx);
5855 } else { 5855 } else {
5856 (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs), 5856 (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs),
5857 (void *)&zp->z_atime, sizeof (zp->z_atime), tx); 5857 (void *)&zp->z_atime, sizeof (zp->z_atime), tx);
5858 zp->z_atime_dirty = 0; 5858 zp->z_atime_dirty = 0;
5859 dmu_tx_commit(tx); 5859 dmu_tx_commit(tx);
5860 } 5860 }
5861 } 
5862 5861
5863 if (zfsvfs->z_log) 5862 if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
5864 zil_commit(zfsvfs->z_log, zp->z_id); 5863 zil_commit(zfsvfs->z_log, zp->z_id);
 5864 }
5865 5865
5866 if (zp->z_sa_hdl == NULL) 5866 if (zp->z_sa_hdl == NULL)
5867 zfs_znode_free(zp); 5867 zfs_znode_free(zp);
5868 else 5868 else
5869 zfs_zinactive(zp); 5869 zfs_zinactive(zp);
5870 rw_exit(&zfsvfs->z_teardown_inactive_lock); 5870 rw_exit(&zfsvfs->z_teardown_inactive_lock);
5871 return 0; 5871 return 0;
5872} 5872}
5873 5873
5874static int 5874static int
5875zfs_netbsd_fid(void *v) 5875zfs_netbsd_fid(void *v)
5876{ 5876{
5877 struct vop_fid_args *ap = v; 5877 struct vop_fid_args *ap = v;