mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-25 18:59:33 +03:00
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 <behlendorf1@llnl.gov> Signed-off-by: Finix Yan <yancw@info2soft.com> Closes #11251 Closes #11256
This commit is contained in:
parent
95a78a035a
commit
ec50cd24ba
@ -499,7 +499,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
|
|||||||
uint64_t blkid, nblks, i;
|
uint64_t blkid, nblks, i;
|
||||||
uint32_t dbuf_flags;
|
uint32_t dbuf_flags;
|
||||||
int err;
|
int err;
|
||||||
zio_t *zio;
|
zio_t *zio = NULL;
|
||||||
|
|
||||||
ASSERT(length <= DMU_MAX_ACCESS);
|
ASSERT(length <= DMU_MAX_ACCESS);
|
||||||
|
|
||||||
@ -531,14 +531,17 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
|
|||||||
}
|
}
|
||||||
dbp = kmem_zalloc(sizeof (dmu_buf_t *) * nblks, KM_SLEEP);
|
dbp = kmem_zalloc(sizeof (dmu_buf_t *) * nblks, KM_SLEEP);
|
||||||
|
|
||||||
zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, ZIO_FLAG_CANFAIL);
|
if (read)
|
||||||
|
zio = zio_root(dn->dn_objset->os_spa, NULL, NULL,
|
||||||
|
ZIO_FLAG_CANFAIL);
|
||||||
blkid = dbuf_whichblock(dn, 0, offset);
|
blkid = dbuf_whichblock(dn, 0, offset);
|
||||||
for (i = 0; i < nblks; i++) {
|
for (i = 0; i < nblks; i++) {
|
||||||
dmu_buf_impl_t *db = dbuf_hold(dn, blkid + i, tag);
|
dmu_buf_impl_t *db = dbuf_hold(dn, blkid + i, tag);
|
||||||
if (db == NULL) {
|
if (db == NULL) {
|
||||||
rw_exit(&dn->dn_struct_rwlock);
|
rw_exit(&dn->dn_struct_rwlock);
|
||||||
dmu_buf_rele_array(dbp, nblks, tag);
|
dmu_buf_rele_array(dbp, nblks, tag);
|
||||||
zio_nowait(zio);
|
if (read)
|
||||||
|
zio_nowait(zio);
|
||||||
return (SET_ERROR(EIO));
|
return (SET_ERROR(EIO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,15 +558,15 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
|
|||||||
}
|
}
|
||||||
rw_exit(&dn->dn_struct_rwlock);
|
rw_exit(&dn->dn_struct_rwlock);
|
||||||
|
|
||||||
/* wait for async i/o */
|
|
||||||
err = zio_wait(zio);
|
|
||||||
if (err) {
|
|
||||||
dmu_buf_rele_array(dbp, nblks, tag);
|
|
||||||
return (err);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wait for other io to complete */
|
|
||||||
if (read) {
|
if (read) {
|
||||||
|
/* wait for async read i/o */
|
||||||
|
err = zio_wait(zio);
|
||||||
|
if (err) {
|
||||||
|
dmu_buf_rele_array(dbp, nblks, tag);
|
||||||
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wait for other io to complete */
|
||||||
for (i = 0; i < nblks; i++) {
|
for (i = 0; i < nblks; i++) {
|
||||||
dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbp[i];
|
dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbp[i];
|
||||||
mutex_enter(&db->db_mtx);
|
mutex_enter(&db->db_mtx);
|
||||||
|
Loading…
Reference in New Issue
Block a user