Skip to content

Commit ec50cd2

Browse files
authored
Avoid unneccessary zio allocation and wait
In function dmu_buf_hold_array_by_dnode, the usage of zio is only for the reading operation. Only create the zio and wait it in the reading scenario as a performance optimization. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Finix Yan <[email protected]> Closes #11251 Closes #11256
1 parent 95a78a0 commit ec50cd2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

module/zfs/dmu.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
499499
uint64_t blkid, nblks, i;
500500
uint32_t dbuf_flags;
501501
int err;
502-
zio_t *zio;
502+
zio_t *zio = NULL;
503503

504504
ASSERT(length <= DMU_MAX_ACCESS);
505505

@@ -531,14 +531,17 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
531531
}
532532
dbp = kmem_zalloc(sizeof (dmu_buf_t *) * nblks, KM_SLEEP);
533533

534-
zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, ZIO_FLAG_CANFAIL);
534+
if (read)
535+
zio = zio_root(dn->dn_objset->os_spa, NULL, NULL,
536+
ZIO_FLAG_CANFAIL);
535537
blkid = dbuf_whichblock(dn, 0, offset);
536538
for (i = 0; i < nblks; i++) {
537539
dmu_buf_impl_t *db = dbuf_hold(dn, blkid + i, tag);
538540
if (db == NULL) {
539541
rw_exit(&dn->dn_struct_rwlock);
540542
dmu_buf_rele_array(dbp, nblks, tag);
541-
zio_nowait(zio);
543+
if (read)
544+
zio_nowait(zio);
542545
return (SET_ERROR(EIO));
543546
}
544547

@@ -555,15 +558,15 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
555558
}
556559
rw_exit(&dn->dn_struct_rwlock);
557560

558-
/* wait for async i/o */
559-
err = zio_wait(zio);
560-
if (err) {
561-
dmu_buf_rele_array(dbp, nblks, tag);
562-
return (err);
563-
}
564-
565-
/* wait for other io to complete */
566561
if (read) {
562+
/* wait for async read i/o */
563+
err = zio_wait(zio);
564+
if (err) {
565+
dmu_buf_rele_array(dbp, nblks, tag);
566+
return (err);
567+
}
568+
569+
/* wait for other io to complete */
567570
for (i = 0; i < nblks; i++) {
568571
dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbp[i];
569572
mutex_enter(&db->db_mtx);

0 commit comments

Comments
 (0)