]> granicus.if.org Git - zfs/commitdiff
Improve performance by using dmu_tx_hold_*_by_dnode()
authorMatthew Ahrens <mahrens@delphix.com>
Tue, 30 Jul 2019 16:18:30 +0000 (09:18 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 30 Jul 2019 16:18:30 +0000 (09:18 -0700)
In zfs_write() and dmu_tx_hold_sa(), we can use dmu_tx_hold_*_by_dnode()
instead of dmu_tx_hold_*(), since we already have a dbuf from the target
dnode in hand.  This eliminates some calls to dnode_hold(), which can be
expensive.  This is especially impactful if several threads are
accessing objects that are in the same block of dnodes, because they
will contend for that dbuf's lock.

We are seeing 10-20% performance wins for the sequential_writes tests in
the performance test suite, when doing >=128K writes to files with
recordsize=8K.

This also removes some unnecessary casts that are in the area.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #9081

module/zfs/dmu_tx.c
module/zfs/sa.c
module/zfs/zfs_vnops.c

index 4f489de5f0efddff27c113f1a5da483ffe4f294b..fcbe3028797e9d5580f322e144954de1d86eafb3 100644 (file)
@@ -1321,7 +1321,10 @@ dmu_tx_hold_sa(dmu_tx_t *tx, sa_handle_t *hdl, boolean_t may_grow)
 
        object = sa_handle_object(hdl);
 
-       dmu_tx_hold_bonus(tx, object);
+       dmu_buf_impl_t *db = (dmu_buf_impl_t *)hdl->sa_bonus;
+       DB_DNODE_ENTER(db);
+       dmu_tx_hold_bonus_by_dnode(tx, DB_DNODE(db));
+       DB_DNODE_EXIT(db);
 
        if (tx->tx_objset->os_sa->sa_master_obj == 0)
                return;
@@ -1343,7 +1346,6 @@ dmu_tx_hold_sa(dmu_tx_t *tx, sa_handle_t *hdl, boolean_t may_grow)
                ASSERT(tx->tx_txg == 0);
                dmu_tx_hold_spill(tx, object);
        } else {
-               dmu_buf_impl_t *db = (dmu_buf_impl_t *)hdl->sa_bonus;
                dnode_t *dn;
 
                DB_DNODE_ENTER(db);
index 56a606962a7f97f3cf8038a5474a05b1f55bc0b8..4999fef345dcd593696b883c60f645f8a073616d 100644 (file)
@@ -1380,7 +1380,7 @@ sa_handle_destroy(sa_handle_t *hdl)
        dmu_buf_rele(hdl->sa_bonus, NULL);
 
        if (hdl->sa_spill)
-               dmu_buf_rele((dmu_buf_t *)hdl->sa_spill, NULL);
+               dmu_buf_rele(hdl->sa_spill, NULL);
        mutex_exit(&hdl->sa_lock);
 
        kmem_cache_free(sa_cache, hdl);
@@ -2028,7 +2028,7 @@ sa_bulk_update_impl(sa_handle_t *hdl, sa_bulk_attr_t *bulk, int count,
                        hdl->sa_spill_tab = NULL;
                }
 
-               dmu_buf_rele((dmu_buf_t *)hdl->sa_spill, NULL);
+               dmu_buf_rele(hdl->sa_spill, NULL);
                hdl->sa_spill = NULL;
        }
 
@@ -2131,13 +2131,13 @@ sa_remove(sa_handle_t *hdl, sa_attr_type_t attr, dmu_tx_t *tx)
 void
 sa_object_info(sa_handle_t *hdl, dmu_object_info_t *doi)
 {
-       dmu_object_info_from_db((dmu_buf_t *)hdl->sa_bonus, doi);
+       dmu_object_info_from_db(hdl->sa_bonus, doi);
 }
 
 void
 sa_object_size(sa_handle_t *hdl, uint32_t *blksize, u_longlong_t *nblocks)
 {
-       dmu_object_size_from_db((dmu_buf_t *)hdl->sa_bonus,
+       dmu_object_size_from_db(hdl->sa_bonus,
            blksize, nblocks);
 }
 
@@ -2150,7 +2150,7 @@ sa_set_userp(sa_handle_t *hdl, void *ptr)
 dmu_buf_t *
 sa_get_db(sa_handle_t *hdl)
 {
-       return ((dmu_buf_t *)hdl->sa_bonus);
+       return (hdl->sa_bonus);
 }
 
 void *
index 2a49293c245cad96c008f7f2ee8b8301263ead0b..7f33aea43d484a5700e538b27c38efe4131b18cd 100644 (file)
@@ -775,7 +775,11 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
                 */
                dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
                dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
-               dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
+               dmu_buf_impl_t *db = (dmu_buf_impl_t *)sa_get_db(zp->z_sa_hdl);
+               DB_DNODE_ENTER(db);
+               dmu_tx_hold_write_by_dnode(tx, DB_DNODE(db), woff,
+                   MIN(n, max_blksz));
+               DB_DNODE_EXIT(db);
                zfs_sa_upgrade_txholds(tx, zp);
                error = dmu_tx_assign(tx, TXG_WAIT);
                if (error) {
@@ -1048,7 +1052,7 @@ zfs_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb, zio_t *zio)
                return (SET_ERROR(ENOENT));
        }
 
-       zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
+       zgd = kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
        zgd->zgd_lwb = lwb;
        zgd->zgd_private = zp;