mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-01-12 19:20:28 +03:00
Convert zio_buf_alloc() consumers
In multiple cases zio_buf_alloc() was used instead of kmem_alloc() or vmem_alloc(). This was often done because the allocations could be large and it was easy to use zfs_buf_alloc() for them. But this isn't ideal for allocations which are small or short lived. In these cases it is better to use kmem_alloc() or vmem_alloc(). If possible we want to avoid the case where we have slabs allocated for kmem caches which are rarely used. Note for small allocations vmem_alloc() will be internally converted to kmem_alloc(). Therefore as long as large allocations are infrequent and short lived the penalty for using vmem_alloc() is small. Reviewed-by: Chunwei Chen <david.chen@osnexus.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #5409
This commit is contained in:
parent
7657defc48
commit
a3fd9d9e15
@ -1020,7 +1020,7 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
|
||||
int max_bonuslen = DN_SLOTS_TO_BONUSLEN(dn->dn_num_slots);
|
||||
|
||||
ASSERT3U(bonuslen, <=, db->db.db_size);
|
||||
db->db.db_data = zio_buf_alloc(max_bonuslen);
|
||||
db->db.db_data = kmem_alloc(max_bonuslen, KM_SLEEP);
|
||||
arc_space_consume(max_bonuslen, ARC_SPACE_BONUS);
|
||||
if (bonuslen < max_bonuslen)
|
||||
bzero(db->db.db_data, max_bonuslen);
|
||||
@ -1132,10 +1132,9 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg)
|
||||
*/
|
||||
ASSERT(dr->dr_txg >= txg - 2);
|
||||
if (db->db_blkid == DMU_BONUS_BLKID) {
|
||||
/* Note that the data bufs here are zio_bufs */
|
||||
dnode_t *dn = DB_DNODE(db);
|
||||
int bonuslen = DN_SLOTS_TO_BONUSLEN(dn->dn_num_slots);
|
||||
dr->dt.dl.dr_data = zio_buf_alloc(bonuslen);
|
||||
dr->dt.dl.dr_data = kmem_alloc(bonuslen, KM_SLEEP);
|
||||
arc_space_consume(bonuslen, ARC_SPACE_BONUS);
|
||||
bcopy(db->db.db_data, dr->dt.dl.dr_data, bonuslen);
|
||||
} else if (refcount_count(&db->db_holds) > db->db_dirtycnt) {
|
||||
@ -2157,7 +2156,7 @@ dbuf_destroy(dmu_buf_impl_t *db)
|
||||
int slots = DB_DNODE(db)->dn_num_slots;
|
||||
int bonuslen = DN_SLOTS_TO_BONUSLEN(slots);
|
||||
ASSERT(db->db.db_data != NULL);
|
||||
zio_buf_free(db->db.db_data, bonuslen);
|
||||
kmem_free(db->db.db_data, bonuslen);
|
||||
arc_space_return(bonuslen, ARC_SPACE_BONUS);
|
||||
db->db_state = DB_UNCACHED;
|
||||
}
|
||||
@ -3304,7 +3303,7 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx)
|
||||
if (*datap != db->db.db_data) {
|
||||
int slots = DB_DNODE(db)->dn_num_slots;
|
||||
int bonuslen = DN_SLOTS_TO_BONUSLEN(slots);
|
||||
zio_buf_free(*datap, bonuslen);
|
||||
kmem_free(*datap, bonuslen);
|
||||
arc_space_return(bonuslen, ARC_SPACE_BONUS);
|
||||
}
|
||||
db->db_data_pending = NULL;
|
||||
|
@ -1690,7 +1690,7 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
||||
|
||||
if ((error = sa_get_spill(hdl)) == 0) {
|
||||
spill_data_size = hdl->sa_spill->db_size;
|
||||
old_data[1] = zio_buf_alloc(spill_data_size);
|
||||
old_data[1] = vmem_alloc(spill_data_size, KM_SLEEP);
|
||||
bcopy(hdl->sa_spill->db_data, old_data[1],
|
||||
hdl->sa_spill->db_size);
|
||||
spill_attr_count =
|
||||
@ -1773,7 +1773,7 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
||||
if (old_data[0])
|
||||
kmem_free(old_data[0], bonus_data_size);
|
||||
if (old_data[1])
|
||||
zio_buf_free(old_data[1], spill_data_size);
|
||||
vmem_free(old_data[1], spill_data_size);
|
||||
kmem_free(attr_desc, sizeof (sa_bulk_attr_t) * attr_count);
|
||||
|
||||
return (error);
|
||||
|
@ -72,7 +72,7 @@ space_map_load(space_map_t *sm, range_tree_t *rt, maptype_t maptype)
|
||||
}
|
||||
|
||||
bufsize = MAX(sm->sm_blksz, SPA_MINBLOCKSIZE);
|
||||
entry_map = zio_buf_alloc(bufsize);
|
||||
entry_map = vmem_alloc(bufsize, KM_SLEEP);
|
||||
|
||||
mutex_exit(sm->sm_lock);
|
||||
if (end > bufsize) {
|
||||
@ -128,7 +128,7 @@ space_map_load(space_map_t *sm, range_tree_t *rt, maptype_t maptype)
|
||||
else
|
||||
range_tree_vacate(rt, NULL, NULL);
|
||||
|
||||
zio_buf_free(entry_map, bufsize);
|
||||
vmem_free(entry_map, bufsize);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ space_map_write(space_map_t *sm, range_tree_t *rt, maptype_t maptype,
|
||||
|
||||
expected_entries = space_map_entries(sm, rt);
|
||||
|
||||
entry_map = zio_buf_alloc(sm->sm_blksz);
|
||||
entry_map = vmem_alloc(sm->sm_blksz, KM_SLEEP);
|
||||
entry_map_end = entry_map + (sm->sm_blksz / sizeof (uint64_t));
|
||||
entry = entry_map;
|
||||
|
||||
@ -335,7 +335,7 @@ space_map_write(space_map_t *sm, range_tree_t *rt, maptype_t maptype,
|
||||
VERIFY3U(range_tree_space(rt), ==, rt_space);
|
||||
VERIFY3U(range_tree_space(rt), ==, total);
|
||||
|
||||
zio_buf_free(entry_map, sm->sm_blksz);
|
||||
vmem_free(entry_map, sm->sm_blksz);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -584,7 +584,7 @@ mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags)
|
||||
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
|
||||
|
||||
sz = zap->zap_dbuf->db_size;
|
||||
mzp = zio_buf_alloc(sz);
|
||||
mzp = vmem_alloc(sz, KM_SLEEP);
|
||||
bcopy(zap->zap_dbuf->db_data, mzp, sz);
|
||||
nchunks = zap->zap_m.zap_num_chunks;
|
||||
|
||||
@ -592,7 +592,7 @@ mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags)
|
||||
err = dmu_object_set_blocksize(zap->zap_objset, zap->zap_object,
|
||||
1ULL << fzap_default_block_shift, 0, tx);
|
||||
if (err) {
|
||||
zio_buf_free(mzp, sz);
|
||||
vmem_free(mzp, sz);
|
||||
return (err);
|
||||
}
|
||||
}
|
||||
@ -619,7 +619,7 @@ mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags)
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
zio_buf_free(mzp, sz);
|
||||
vmem_free(mzp, sz);
|
||||
*zapp = zap;
|
||||
return (err);
|
||||
}
|
||||
|
@ -203,13 +203,13 @@ zfs_sa_get_xattr(znode_t *zp)
|
||||
return (error);
|
||||
}
|
||||
|
||||
obj = zio_buf_alloc(size);
|
||||
obj = vmem_alloc(size, KM_SLEEP);
|
||||
|
||||
error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), obj, size);
|
||||
if (error == 0)
|
||||
error = nvlist_unpack(obj, size, &zp->z_xattr_cached, KM_SLEEP);
|
||||
|
||||
zio_buf_free(obj, size);
|
||||
vmem_free(obj, size);
|
||||
|
||||
return (error);
|
||||
}
|
||||
@ -233,7 +233,7 @@ zfs_sa_set_xattr(znode_t *zp)
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
obj = zio_buf_alloc(size);
|
||||
obj = vmem_alloc(size, KM_SLEEP);
|
||||
|
||||
error = nvlist_pack(zp->z_xattr_cached, &obj, &size,
|
||||
NV_ENCODE_XDR, KM_SLEEP);
|
||||
@ -253,7 +253,7 @@ zfs_sa_set_xattr(znode_t *zp)
|
||||
dmu_tx_commit(tx);
|
||||
}
|
||||
out_free:
|
||||
zio_buf_free(obj, size);
|
||||
vmem_free(obj, size);
|
||||
out:
|
||||
return (error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user