Skip to content

Commit

Permalink
Commented out all dn_struct_rwlock RW_READER locks for benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhutter committed Jul 4, 2017
1 parent 682ce10 commit 7481237
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 68 deletions.
42 changes: 21 additions & 21 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ dbuf_find_bonus(objset_t *os, uint64_t object)
dmu_buf_impl_t *db = NULL;

if (dnode_hold(os, object, FTAG, &dn) == 0) {
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
if (dn->dn_bonus != NULL) {
db = dn->dn_bonus;
mutex_enter(&db->db_mtx);
}
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
dnode_rele(dn, FTAG);
}
return (db);
Expand Down Expand Up @@ -1009,7 +1009,7 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
dn = DB_DNODE(db);
ASSERT(!refcount_is_zero(&db->db_holds));
/* We need the struct_rwlock to prevent db_blkptr from changing. */
ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
// ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
ASSERT(MUTEX_HELD(&db->db_mtx));
ASSERT(db->db_state == DB_UNCACHED);
ASSERT(db->db_buf == NULL);
Expand Down Expand Up @@ -1179,8 +1179,8 @@ dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)

DB_DNODE_ENTER(db);
dn = DB_DNODE(db);
if ((flags & DB_RF_HAVESTRUCT) == 0)
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// if ((flags & DB_RF_HAVESTRUCT) == 0)
// rw_enter(&dn->dn_struct_rwlock, RW_READER);

prefetch = db->db_level == 0 && db->db_blkid != DMU_BONUS_BLKID &&
(flags & DB_RF_NOPREFETCH) == 0 && dn != NULL &&
Expand All @@ -1203,8 +1203,8 @@ dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
mutex_exit(&db->db_mtx);
if (prefetch)
dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE);
if ((flags & DB_RF_HAVESTRUCT) == 0)
rw_exit(&dn->dn_struct_rwlock);
// if ((flags & DB_RF_HAVESTRUCT) == 0)
// rw_exit(&dn->dn_struct_rwlock);
DB_DNODE_EXIT(db);
} else if (db->db_state == DB_UNCACHED) {
spa_t *spa = dn->dn_objset->os_spa;
Expand All @@ -1222,8 +1222,8 @@ dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
if (!err && prefetch)
dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE);

if ((flags & DB_RF_HAVESTRUCT) == 0)
rw_exit(&dn->dn_struct_rwlock);
// if ((flags & DB_RF_HAVESTRUCT) == 0)
// rw_exit(&dn->dn_struct_rwlock);
DB_DNODE_EXIT(db);

if (!err && need_wait)
Expand All @@ -1241,7 +1241,7 @@ dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
if (prefetch)
dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE);
if ((flags & DB_RF_HAVESTRUCT) == 0)
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
DB_DNODE_EXIT(db);

/* Skip the wait per the caller's request. */
Expand Down Expand Up @@ -1743,7 +1743,7 @@ dbuf_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx)
* looking at db_blkptr.
*/
if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) {
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
drop_struct_lock = TRUE;
}

Expand Down Expand Up @@ -1773,8 +1773,8 @@ dbuf_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx)
ASSERT(parent != NULL);
parent_held = TRUE;
}
if (drop_struct_lock)
rw_exit(&dn->dn_struct_rwlock);
// if (drop_struct_lock)
// rw_exit(&dn->dn_struct_rwlock);
ASSERT3U(db->db_level+1, ==, parent->db_level);
di = dbuf_dirty(parent, tx);
if (parent_held)
Expand Down Expand Up @@ -1803,8 +1803,8 @@ dbuf_dirty(dmu_buf_impl_t *db, dmu_tx_t *tx)
ASSERT(!list_link_active(&dr->dr_dirty_node));
list_insert_tail(&dn->dn_dirty_records[txgoff], dr);
mutex_exit(&dn->dn_mtx);
if (drop_struct_lock)
rw_exit(&dn->dn_struct_rwlock);
// if (drop_struct_lock)
// rw_exit(&dn->dn_struct_rwlock);
}

dnode_setdirty(dn, tx);
Expand Down Expand Up @@ -2226,7 +2226,7 @@ dbuf_findbp(dnode_t *dn, int level, uint64_t blkid, int fail_sparse,
epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;

ASSERT3U(level * epbs, <, 64);
ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
// ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
/*
* This assertion shouldn't trip as long as the max indirect block size
* is less than 1M. The reason for this is that up to that point,
Expand Down Expand Up @@ -2299,7 +2299,7 @@ dbuf_create(dnode_t *dn, uint8_t level, uint64_t blkid,
objset_t *os = dn->dn_objset;
dmu_buf_impl_t *db, *odb;

ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
// ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
ASSERT(dn->dn_type != DMU_OT_NONE);

db = kmem_cache_alloc(dbuf_kmem_cache, KM_SLEEP);
Expand Down Expand Up @@ -2501,7 +2501,7 @@ dbuf_prefetch(dnode_t *dn, int64_t level, uint64_t blkid, zio_priority_t prio,
dsl_dataset_t *ds;

ASSERT(blkid != DMU_BONUS_BLKID);
ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));
// ASSERT(RW_LOCK_HELD(&dn->dn_struct_rwlock));

if (blkid > dn->dn_maxblkid)
return;
Expand Down Expand Up @@ -2623,7 +2623,7 @@ __dbuf_hold_impl(struct dbuf_hold_impl_data *dh)
dh->dh_parent = NULL;

ASSERT(dh->dh_blkid != DMU_BONUS_BLKID);
ASSERT(RW_LOCK_HELD(&dh->dh_dn->dn_struct_rwlock));
// ASSERT(RW_LOCK_HELD(&dh->dh_dn->dn_struct_rwlock));
ASSERT3U(dh->dh_dn->dn_nlevels, >, dh->dh_level);

*(dh->dh_dbp) = NULL;
Expand Down Expand Up @@ -3102,10 +3102,10 @@ dbuf_check_blkptr(dnode_t *dn, dmu_buf_impl_t *db)
ASSERT(dn->dn_phys->dn_nlevels > 1);
if (parent == NULL) {
mutex_exit(&db->db_mtx);
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
parent = dbuf_hold_level(dn, db->db_level + 1,
db->db_blkid >> epbs, db);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
mutex_enter(&db->db_mtx);
db->db_parent = parent;
}
Expand Down
53 changes: 28 additions & 25 deletions module/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ dmu_buf_hold_noread_by_dnode(dnode_t *dn, uint64_t offset,
dmu_buf_impl_t *db;

blkid = dbuf_whichblock(dn, 0, offset);
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
db = dbuf_hold(dn, blkid, tag);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);

if (db == NULL) {
*dbp = NULL;
Expand All @@ -175,9 +175,9 @@ dmu_buf_hold_noread(objset_t *os, uint64_t object, uint64_t offset,
if (err)
return (err);
blkid = dbuf_whichblock(dn, 0, offset);
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
db = dbuf_hold(dn, blkid, tag);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
dnode_rele(dn, FTAG);

if (db == NULL) {
Expand Down Expand Up @@ -326,15 +326,17 @@ dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **dbp)
dnode_t *dn;
dmu_buf_impl_t *db;
int error;
int writer = 0;

error = dnode_hold(os, object, FTAG, &dn);
if (error)
return (error);

rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
if (dn->dn_bonus == NULL) {
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
writer = 1;
if (dn->dn_bonus == NULL)
dbuf_create_bonus(dn);
}
Expand All @@ -351,7 +353,8 @@ dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **dbp)
* hold and incrementing the dbuf count to ensure that dnode_move() sees
* a dnode hold for every dbuf.
*/
rw_exit(&dn->dn_struct_rwlock);
if (writer)
rw_exit(&dn->dn_struct_rwlock);

dnode_rele(dn, FTAG);

Expand All @@ -376,13 +379,13 @@ dmu_spill_hold_by_dnode(dnode_t *dn, uint32_t flags, void *tag, dmu_buf_t **dbp)
dmu_buf_impl_t *db = NULL;
int err;

if ((flags & DB_RF_HAVESTRUCT) == 0)
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// if ((flags & DB_RF_HAVESTRUCT) == 0)
// rw_enter(&dn->dn_struct_rwlock, RW_READER);

db = dbuf_hold(dn, DMU_SPILL_BLKID, tag);

if ((flags & DB_RF_HAVESTRUCT) == 0)
rw_exit(&dn->dn_struct_rwlock);
// if ((flags & DB_RF_HAVESTRUCT) == 0)
// rw_exit(&dn->dn_struct_rwlock);

if (db == NULL) {
*dbp = NULL;
Expand Down Expand Up @@ -411,7 +414,7 @@ dmu_spill_hold_existing(dmu_buf_t *bonus, void *tag, dmu_buf_t **dbp)
if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_SA) {
err = SET_ERROR(EINVAL);
} else {
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);

if (!dn->dn_have_spill) {
err = SET_ERROR(ENOENT);
Expand All @@ -420,7 +423,7 @@ dmu_spill_hold_existing(dmu_buf_t *bonus, void *tag, dmu_buf_t **dbp)
DB_RF_HAVESTRUCT | DB_RF_CANFAIL, tag, dbp);
}

rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
}

DB_DNODE_EXIT(db);
Expand Down Expand Up @@ -468,7 +471,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
dbuf_flags = DB_RF_CANFAIL | DB_RF_NEVERWAIT | DB_RF_HAVESTRUCT |
DB_RF_NOPREFETCH;

rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
if (dn->dn_datablkshift) {
int blkshift = dn->dn_datablkshift;
nblks = (P2ROUNDUP(offset + length, 1ULL << blkshift) -
Expand All @@ -481,7 +484,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
os_dsl_dataset->ds_object,
(longlong_t)dn->dn_object, dn->dn_datablksz,
(longlong_t)offset, (longlong_t)length);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
return (SET_ERROR(EIO));
}
nblks = 1;
Expand All @@ -493,7 +496,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
for (i = 0; i < nblks; i++) {
dmu_buf_impl_t *db = dbuf_hold(dn, blkid + i, tag);
if (db == NULL) {
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
dmu_buf_rele_array(dbp, nblks, tag);
zio_nowait(zio);
return (SET_ERROR(EIO));
Expand All @@ -510,7 +513,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
dmu_zfetch(&dn->dn_zfetch, blkid, nblks,
read && DNODE_IS_CACHEABLE(dn));
}
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);

/* wait for async i/o */
err = zio_wait(zio);
Expand Down Expand Up @@ -618,11 +621,11 @@ dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
if (object == 0 || object >= DN_MAX_OBJECT)
return;

rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
blkid = dbuf_whichblock(dn, level,
object * sizeof (dnode_phys_t));
dbuf_prefetch(dn, level, blkid, pri, 0);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
return;
}

Expand All @@ -635,7 +638,7 @@ dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
if (err != 0)
return;

rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
/*
* offset + len - 1 is the last byte we want to prefetch for, and offset
* is the first. Then dbuf_whichblk(dn, level, off + len - 1) is the
Expand All @@ -658,7 +661,7 @@ dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
dbuf_prefetch(dn, level, blkid + i, pri, 0);
}

rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);

dnode_rele(dn, FTAG);
}
Expand Down Expand Up @@ -1479,10 +1482,10 @@ dmu_assign_arcbuf(dmu_buf_t *handle, uint64_t offset, arc_buf_t *buf,

DB_DNODE_ENTER(dbuf);
dn = DB_DNODE(dbuf);
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
blkid = dbuf_whichblock(dn, 0, offset);
VERIFY((db = dbuf_hold(dn, blkid, FTAG)) != NULL);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
DB_DNODE_EXIT(dbuf);

/*
Expand Down Expand Up @@ -2067,13 +2070,13 @@ __dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi)
void
dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi)
{
rw_enter(&dn->dn_struct_rwlock, RW_READER);
// rw_enter(&dn->dn_struct_rwlock, RW_READER);
mutex_enter(&dn->dn_mtx);

__dmu_object_info_from_dnode(dn, doi);

mutex_exit(&dn->dn_mtx);
rw_exit(&dn->dn_struct_rwlock);
// rw_exit(&dn->dn_struct_rwlock);
}

/*
Expand Down
Loading

0 comments on commit 7481237

Please sign in to comment.