Skip to content

Commit a81b812

Browse files
authored
Revert Consolidate arc_buf allocation checks
This reverts commit 13fac09. Per the discussion in #11531, the reverted commit---which intended only to be a cleanup commit---introduced a subtle, unintended change in behavior. Care was taken to partially revert and then reapply 10b3c7f which would otherwise have caused a conflict. These changes were squashed in to this commit. Reviewed-by: Brian Behlendorf <[email protected]> Suggested-by: @chrisrd Suggested-by: [email protected] Signed-off-by: Antonio Russo <[email protected]> Closes #11531 Closes #12227
1 parent 29274c9 commit a81b812

File tree

1 file changed

+77
-44
lines changed

1 file changed

+77
-44
lines changed

module/zfs/dbuf.c

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,42 +1152,6 @@ dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
11521152
db->db.db_data = buf->b_data;
11531153
}
11541154

1155-
static arc_buf_t *
1156-
dbuf_alloc_arcbuf_from_arcbuf(dmu_buf_impl_t *db, arc_buf_t *data)
1157-
{
1158-
objset_t *os = db->db_objset;
1159-
spa_t *spa = os->os_spa;
1160-
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
1161-
enum zio_compress compress_type;
1162-
uint8_t complevel;
1163-
int psize, lsize;
1164-
1165-
psize = arc_buf_size(data);
1166-
lsize = arc_buf_lsize(data);
1167-
compress_type = arc_get_compression(data);
1168-
complevel = arc_get_complevel(data);
1169-
1170-
if (arc_is_encrypted(data)) {
1171-
boolean_t byteorder;
1172-
uint8_t salt[ZIO_DATA_SALT_LEN];
1173-
uint8_t iv[ZIO_DATA_IV_LEN];
1174-
uint8_t mac[ZIO_DATA_MAC_LEN];
1175-
dnode_t *dn = DB_DNODE(db);
1176-
1177-
arc_get_raw_params(data, &byteorder, salt, iv, mac);
1178-
data = arc_alloc_raw_buf(spa, db, dmu_objset_id(os),
1179-
byteorder, salt, iv, mac, dn->dn_type, psize, lsize,
1180-
compress_type, complevel);
1181-
} else if (compress_type != ZIO_COMPRESS_OFF) {
1182-
ASSERT3U(type, ==, ARC_BUFC_DATA);
1183-
data = arc_alloc_compressed_buf(spa, db,
1184-
psize, lsize, compress_type, complevel);
1185-
} else {
1186-
data = arc_alloc_buf(spa, db, type, psize);
1187-
}
1188-
return (data);
1189-
}
1190-
11911155
static arc_buf_t *
11921156
dbuf_alloc_arcbuf(dmu_buf_impl_t *db)
11931157
{
@@ -1635,9 +1599,35 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg)
16351599
arc_space_consume(bonuslen, ARC_SPACE_BONUS);
16361600
bcopy(db->db.db_data, dr->dt.dl.dr_data, bonuslen);
16371601
} else if (zfs_refcount_count(&db->db_holds) > db->db_dirtycnt) {
1638-
arc_buf_t *buf = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf);
1639-
dr->dt.dl.dr_data = buf;
1640-
bcopy(db->db.db_data, buf->b_data, arc_buf_size(buf));
1602+
dnode_t *dn = DB_DNODE(db);
1603+
int size = arc_buf_size(db->db_buf);
1604+
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
1605+
spa_t *spa = db->db_objset->os_spa;
1606+
enum zio_compress compress_type =
1607+
arc_get_compression(db->db_buf);
1608+
uint8_t complevel = arc_get_complevel(db->db_buf);
1609+
1610+
if (arc_is_encrypted(db->db_buf)) {
1611+
boolean_t byteorder;
1612+
uint8_t salt[ZIO_DATA_SALT_LEN];
1613+
uint8_t iv[ZIO_DATA_IV_LEN];
1614+
uint8_t mac[ZIO_DATA_MAC_LEN];
1615+
1616+
arc_get_raw_params(db->db_buf, &byteorder, salt,
1617+
iv, mac);
1618+
dr->dt.dl.dr_data = arc_alloc_raw_buf(spa, db,
1619+
dmu_objset_id(dn->dn_objset), byteorder, salt, iv,
1620+
mac, dn->dn_type, size, arc_buf_lsize(db->db_buf),
1621+
compress_type, complevel);
1622+
} else if (compress_type != ZIO_COMPRESS_OFF) {
1623+
ASSERT3U(type, ==, ARC_BUFC_DATA);
1624+
dr->dt.dl.dr_data = arc_alloc_compressed_buf(spa, db,
1625+
size, arc_buf_lsize(db->db_buf), compress_type,
1626+
complevel);
1627+
} else {
1628+
dr->dt.dl.dr_data = arc_alloc_buf(spa, db, type, size);
1629+
}
1630+
bcopy(db->db.db_data, dr->dt.dl.dr_data->b_data, size);
16411631
} else {
16421632
db->db_buf = NULL;
16431633
dbuf_clear_data(db);
@@ -3438,10 +3428,30 @@ noinline static void
34383428
dbuf_hold_copy(dnode_t *dn, dmu_buf_impl_t *db)
34393429
{
34403430
dbuf_dirty_record_t *dr = db->db_data_pending;
3441-
arc_buf_t *newdata, *data = dr->dt.dl.dr_data;
3431+
arc_buf_t *data = dr->dt.dl.dr_data;
3432+
enum zio_compress compress_type = arc_get_compression(data);
3433+
uint8_t complevel = arc_get_complevel(data);
3434+
3435+
if (arc_is_encrypted(data)) {
3436+
boolean_t byteorder;
3437+
uint8_t salt[ZIO_DATA_SALT_LEN];
3438+
uint8_t iv[ZIO_DATA_IV_LEN];
3439+
uint8_t mac[ZIO_DATA_MAC_LEN];
3440+
3441+
arc_get_raw_params(data, &byteorder, salt, iv, mac);
3442+
dbuf_set_data(db, arc_alloc_raw_buf(dn->dn_objset->os_spa, db,
3443+
dmu_objset_id(dn->dn_objset), byteorder, salt, iv, mac,
3444+
dn->dn_type, arc_buf_size(data), arc_buf_lsize(data),
3445+
compress_type, complevel));
3446+
} else if (compress_type != ZIO_COMPRESS_OFF) {
3447+
dbuf_set_data(db, arc_alloc_compressed_buf(
3448+
dn->dn_objset->os_spa, db, arc_buf_size(data),
3449+
arc_buf_lsize(data), compress_type, complevel));
3450+
} else {
3451+
dbuf_set_data(db, arc_alloc_buf(dn->dn_objset->os_spa, db,
3452+
DBUF_GET_BUFC_TYPE(db), db->db.db_size));
3453+
}
34423454

3443-
newdata = dbuf_alloc_arcbuf_from_arcbuf(db, data);
3444-
dbuf_set_data(db, newdata);
34453455
rw_enter(&db->db_rwlock, RW_WRITER);
34463456
bcopy(data->b_data, db->db.db_data, arc_buf_size(data));
34473457
rw_exit(&db->db_rwlock);
@@ -4363,8 +4373,31 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx)
43634373
* objects only modified in the syncing context (e.g.
43644374
* DNONE_DNODE blocks).
43654375
*/
4366-
*datap = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf);
4367-
bcopy(db->db.db_data, (*datap)->b_data, arc_buf_size(*datap));
4376+
int psize = arc_buf_size(*datap);
4377+
int lsize = arc_buf_lsize(*datap);
4378+
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
4379+
enum zio_compress compress_type = arc_get_compression(*datap);
4380+
uint8_t complevel = arc_get_complevel(*datap);
4381+
4382+
if (arc_is_encrypted(*datap)) {
4383+
boolean_t byteorder;
4384+
uint8_t salt[ZIO_DATA_SALT_LEN];
4385+
uint8_t iv[ZIO_DATA_IV_LEN];
4386+
uint8_t mac[ZIO_DATA_MAC_LEN];
4387+
4388+
arc_get_raw_params(*datap, &byteorder, salt, iv, mac);
4389+
*datap = arc_alloc_raw_buf(os->os_spa, db,
4390+
dmu_objset_id(os), byteorder, salt, iv, mac,
4391+
dn->dn_type, psize, lsize, compress_type,
4392+
complevel);
4393+
} else if (compress_type != ZIO_COMPRESS_OFF) {
4394+
ASSERT3U(type, ==, ARC_BUFC_DATA);
4395+
*datap = arc_alloc_compressed_buf(os->os_spa, db,
4396+
psize, lsize, compress_type, complevel);
4397+
} else {
4398+
*datap = arc_alloc_buf(os->os_spa, db, type, psize);
4399+
}
4400+
bcopy(db->db.db_data, (*datap)->b_data, psize);
43684401
}
43694402
db->db_data_pending = dr;
43704403

0 commit comments

Comments
 (0)