Skip to content

Commit

Permalink
Make ZIL operations on zvols use _by_dnode routines
Browse files Browse the repository at this point in the history
This continues what was started in 0eef1bd by
fully converting zvols to avoid unnecessary dnode_hold() calls. This saves a
small amount of CPU time and slightly improves latencies on synchronous
operations on zvols.

Signed-off-by: Richard Yao <richard.yao@prophetstor.com>
  • Loading branch information
Richard Yao committed Jun 9, 2017
1 parent 8264410 commit a1d2461
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
6 changes: 6 additions & 0 deletions module/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ int
dmu_read_by_dnode(dnode_t *dn, uint64_t offset, uint64_t size, void *buf,
uint32_t flags)
{
if (size == 0)
return (0);

return (dmu_read_impl(dn, offset, size, buf, flags));
}

Expand Down Expand Up @@ -1342,6 +1345,9 @@ dmu_write_uio_dnode(dnode_t *dn, uio_t *uio, uint64_t size, dmu_tx_t *tx)
int err = 0;
int i;

if (size == 0)
return (0);

err = dmu_buf_hold_array_by_dnode(dn, uio->uio_loffset, size,
FALSE, FTAG, &numbufs, &dbp, DMU_READ_PREFETCH);
if (err)
Expand Down
23 changes: 11 additions & 12 deletions module/zfs/zvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct zvol_state {
uint32_t zv_changed; /* disk changed */
zilog_t *zv_zilog; /* ZIL handle */
zfs_rlock_t zv_range_lock; /* range lock */
dmu_buf_t *zv_dbuf; /* bonus handle */
dmu_buf_t *zv_dn; /* bonus dnode */
dev_t zv_dev; /* device id */
struct gendisk *zv_disk; /* generic disk */
struct request_queue *zv_queue; /* request queue */
Expand Down Expand Up @@ -647,8 +647,8 @@ zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
itx = zil_itx_create(TX_WRITE, sizeof (*lr) +
(write_state == WR_COPIED ? len : 0));
lr = (lr_write_t *)&itx->itx_lr;
if (write_state == WR_COPIED && dmu_read(zv->zv_objset,
ZVOL_OBJ, offset, len, lr+1, DMU_READ_NO_PREFETCH) != 0) {
if (write_state == WR_COPIED && dmu_read_by_dnode(zv->zv_dn,
offset, len, lr+1, DMU_READ_NO_PREFETCH) != 0) {
zil_itx_destroy(itx);
itx = zil_itx_create(TX_WRITE, sizeof (*lr));
lr = (lr_write_t *)&itx->itx_lr;
Expand Down Expand Up @@ -729,7 +729,7 @@ zvol_write(void *arg)
dmu_tx_abort(tx);
break;
}
error = dmu_write_uio_dbuf(zv->zv_dbuf, &uio, bytes, tx);
error = dmu_write_uio_dnode(zv->zv_dn, &uio, bytes, tx);
if (error == 0)
zvol_log_write(zv, tx, off, bytes, sync);
dmu_tx_commit(tx);
Expand Down Expand Up @@ -854,7 +854,7 @@ zvol_read(void *arg)
if (bytes > volsize - uio.uio_loffset)
bytes = volsize - uio.uio_loffset;

error = dmu_read_uio_dbuf(zv->zv_dbuf, &uio, bytes);
error = dmu_read_uio_dnode(zv->zv_dn, &uio, bytes);
if (error) {
/* convert checksum errors into IO errors */
if (error == ECKSUM)
Expand Down Expand Up @@ -978,8 +978,6 @@ static int
zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
{
zvol_state_t *zv = arg;
objset_t *os = zv->zv_objset;
uint64_t object = ZVOL_OBJ;
uint64_t offset = lr->lr_offset;
uint64_t size = lr->lr_length;
blkptr_t *bp = &lr->lr_blkptr;
Expand All @@ -1003,12 +1001,12 @@ zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
* we don't have to write the data twice.
*/
if (buf != NULL) { /* immediate write */
error = dmu_read(os, object, offset, size, buf,
error = dmu_read_by_dnode(zv->zv_dn, offset, size, buf,
DMU_READ_NO_PREFETCH);
} else {
size = zv->zv_volblocksize;
offset = P2ALIGN_TYPED(offset, size, uint64_t);
error = dmu_buf_hold(os, object, offset, zgd, &db,
error = dmu_buf_hold_by_dnode(zv->zv_dn, offset, zgd, &db,
DMU_READ_NO_PREFETCH);
if (error == 0) {
blkptr_t *obp = dmu_buf_get_blkptr(db);
Expand Down Expand Up @@ -1070,6 +1068,7 @@ zvol_setup_zv(zvol_state_t *zv)
int error;
uint64_t ro;
objset_t *os = zv->zv_objset;
dmu_buf_t *db;

error = dsl_prop_get_integer(zv->zv_name, "readonly", &ro, NULL);
if (error)
Expand All @@ -1079,7 +1078,7 @@ zvol_setup_zv(zvol_state_t *zv)
if (error)
return (SET_ERROR(error));

error = dmu_bonus_hold(os, ZVOL_OBJ, zv, &zv->zv_dbuf);
error = dnode_hold(os, ZVOL_OBJ, FTAG, &zv->zv_dn);
if (error)
return (SET_ERROR(error));

Expand Down Expand Up @@ -1108,8 +1107,8 @@ zvol_shutdown_zv(zvol_state_t *zv)
zil_close(zv->zv_zilog);
zv->zv_zilog = NULL;

dmu_buf_rele(zv->zv_dbuf, zv);
zv->zv_dbuf = NULL;
dnode_rele(zv->zv_dn, FTAG);
zv->zv_dn = NULL;

/*
* Evict cached data
Expand Down

0 comments on commit a1d2461

Please sign in to comment.