From 282cf53337d6156e5dcb7212553b0db708713b59 Mon Sep 17 00:00:00 2001 From: Antonio Russo Date: Wed, 17 Mar 2021 19:19:07 -0600 Subject: [PATCH 1/3] Partially revert "Add zstd support to zfs" In preparation for reverting 13fac09868, we partially revert 10b3c7f5e4, within dbuf_alloc_arcbuf_from_arcbuf, which otherwise would conflict. Signed-off-by: Antonio Russo --- module/zfs/dbuf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c index 9d741545fae3..f6ca1b56370a 100644 --- a/module/zfs/dbuf.c +++ b/module/zfs/dbuf.c @@ -1097,13 +1097,11 @@ dbuf_alloc_arcbuf_from_arcbuf(dmu_buf_impl_t *db, arc_buf_t *data) spa_t *spa = os->os_spa; arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); enum zio_compress compress_type; - uint8_t complevel; int psize, lsize; psize = arc_buf_size(data); lsize = arc_buf_lsize(data); compress_type = arc_get_compression(data); - complevel = arc_get_complevel(data); if (arc_is_encrypted(data)) { boolean_t byteorder; @@ -1115,11 +1113,11 @@ dbuf_alloc_arcbuf_from_arcbuf(dmu_buf_impl_t *db, arc_buf_t *data) arc_get_raw_params(data, &byteorder, salt, iv, mac); data = arc_alloc_raw_buf(spa, db, dmu_objset_id(os), byteorder, salt, iv, mac, dn->dn_type, psize, lsize, - compress_type, complevel); + compress_type); } else if (compress_type != ZIO_COMPRESS_OFF) { ASSERT3U(type, ==, ARC_BUFC_DATA); data = arc_alloc_compressed_buf(spa, db, - psize, lsize, compress_type, complevel); + psize, lsize, compress_type); } else { data = arc_alloc_buf(spa, db, type, psize); } From cbdbe6927f229853e8887e32258c3b0060559f8c Mon Sep 17 00:00:00 2001 From: Antonio Russo Date: Wed, 17 Mar 2021 19:20:14 -0600 Subject: [PATCH 2/3] Revert "Consolidate arc_buf allocation checks" This reverts commit 13fac09868b4e4e08cc3ef7b937ac277c1c407b1. Per the discussion in #11531, the reverted commit---which intended only to be a cleanup commit---introduced a subtle, unintended change in behavior. Suggested-by: @chrisrd Suggested-by: robn@despairlabs.com Signed-off-by: Antonio Russo --- module/zfs/dbuf.c | 114 +++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 42 deletions(-) diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c index f6ca1b56370a..304c353f2b32 100644 --- a/module/zfs/dbuf.c +++ b/module/zfs/dbuf.c @@ -1090,40 +1090,6 @@ dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf) db->db.db_data = buf->b_data; } -static arc_buf_t * -dbuf_alloc_arcbuf_from_arcbuf(dmu_buf_impl_t *db, arc_buf_t *data) -{ - objset_t *os = db->db_objset; - spa_t *spa = os->os_spa; - arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); - enum zio_compress compress_type; - int psize, lsize; - - psize = arc_buf_size(data); - lsize = arc_buf_lsize(data); - compress_type = arc_get_compression(data); - - if (arc_is_encrypted(data)) { - boolean_t byteorder; - uint8_t salt[ZIO_DATA_SALT_LEN]; - uint8_t iv[ZIO_DATA_IV_LEN]; - uint8_t mac[ZIO_DATA_MAC_LEN]; - dnode_t *dn = DB_DNODE(db); - - arc_get_raw_params(data, &byteorder, salt, iv, mac); - data = arc_alloc_raw_buf(spa, db, dmu_objset_id(os), - byteorder, salt, iv, mac, dn->dn_type, psize, lsize, - compress_type); - } else if (compress_type != ZIO_COMPRESS_OFF) { - ASSERT3U(type, ==, ARC_BUFC_DATA); - data = arc_alloc_compressed_buf(spa, db, - psize, lsize, compress_type); - } else { - data = arc_alloc_buf(spa, db, type, psize); - } - return (data); -} - static arc_buf_t * dbuf_alloc_arcbuf(dmu_buf_impl_t *db) { @@ -1571,9 +1537,33 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg) arc_space_consume(bonuslen, ARC_SPACE_BONUS); bcopy(db->db.db_data, dr->dt.dl.dr_data, bonuslen); } else if (zfs_refcount_count(&db->db_holds) > db->db_dirtycnt) { - arc_buf_t *buf = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf); - dr->dt.dl.dr_data = buf; - bcopy(db->db.db_data, buf->b_data, arc_buf_size(buf)); + dnode_t *dn = DB_DNODE(db); + int size = arc_buf_size(db->db_buf); + arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); + spa_t *spa = db->db_objset->os_spa; + enum zio_compress compress_type = + arc_get_compression(db->db_buf); + + if (arc_is_encrypted(db->db_buf)) { + boolean_t byteorder; + uint8_t salt[ZIO_DATA_SALT_LEN]; + uint8_t iv[ZIO_DATA_IV_LEN]; + uint8_t mac[ZIO_DATA_MAC_LEN]; + + arc_get_raw_params(db->db_buf, &byteorder, salt, + iv, mac); + dr->dt.dl.dr_data = arc_alloc_raw_buf(spa, db, + dmu_objset_id(dn->dn_objset), byteorder, salt, iv, + mac, dn->dn_type, size, arc_buf_lsize(db->db_buf), + compress_type); + } else if (compress_type != ZIO_COMPRESS_OFF) { + ASSERT3U(type, ==, ARC_BUFC_DATA); + dr->dt.dl.dr_data = arc_alloc_compressed_buf(spa, db, + size, arc_buf_lsize(db->db_buf), compress_type); + } else { + dr->dt.dl.dr_data = arc_alloc_buf(spa, db, type, size); + } + bcopy(db->db.db_data, dr->dt.dl.dr_data->b_data, size); } else { db->db_buf = NULL; dbuf_clear_data(db); @@ -3374,10 +3364,29 @@ noinline static void dbuf_hold_copy(dnode_t *dn, dmu_buf_impl_t *db) { dbuf_dirty_record_t *dr = db->db_data_pending; - arc_buf_t *newdata, *data = dr->dt.dl.dr_data; + arc_buf_t *data = dr->dt.dl.dr_data; + enum zio_compress compress_type = arc_get_compression(data); + + if (arc_is_encrypted(data)) { + boolean_t byteorder; + uint8_t salt[ZIO_DATA_SALT_LEN]; + uint8_t iv[ZIO_DATA_IV_LEN]; + uint8_t mac[ZIO_DATA_MAC_LEN]; + + arc_get_raw_params(data, &byteorder, salt, iv, mac); + dbuf_set_data(db, arc_alloc_raw_buf(dn->dn_objset->os_spa, db, + dmu_objset_id(dn->dn_objset), byteorder, salt, iv, mac, + dn->dn_type, arc_buf_size(data), arc_buf_lsize(data), + compress_type)); + } else if (compress_type != ZIO_COMPRESS_OFF) { + dbuf_set_data(db, arc_alloc_compressed_buf( + dn->dn_objset->os_spa, db, arc_buf_size(data), + arc_buf_lsize(data), compress_type)); + } else { + dbuf_set_data(db, arc_alloc_buf(dn->dn_objset->os_spa, db, + DBUF_GET_BUFC_TYPE(db), db->db.db_size)); + } - newdata = dbuf_alloc_arcbuf_from_arcbuf(db, data); - dbuf_set_data(db, newdata); rw_enter(&db->db_rwlock, RW_WRITER); bcopy(data->b_data, db->db.db_data, arc_buf_size(data)); rw_exit(&db->db_rwlock); @@ -4299,8 +4308,29 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx) * objects only modified in the syncing context (e.g. * DNONE_DNODE blocks). */ - *datap = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf); - bcopy(db->db.db_data, (*datap)->b_data, arc_buf_size(*datap)); + int psize = arc_buf_size(*datap); + int lsize = arc_buf_lsize(*datap); + arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); + enum zio_compress compress_type = arc_get_compression(*datap); + + if (arc_is_encrypted(*datap)) { + boolean_t byteorder; + uint8_t salt[ZIO_DATA_SALT_LEN]; + uint8_t iv[ZIO_DATA_IV_LEN]; + uint8_t mac[ZIO_DATA_MAC_LEN]; + + arc_get_raw_params(*datap, &byteorder, salt, iv, mac); + *datap = arc_alloc_raw_buf(os->os_spa, db, + dmu_objset_id(os), byteorder, salt, iv, mac, + dn->dn_type, psize, lsize, compress_type); + } else if (compress_type != ZIO_COMPRESS_OFF) { + ASSERT3U(type, ==, ARC_BUFC_DATA); + *datap = arc_alloc_compressed_buf(os->os_spa, db, + psize, lsize, compress_type); + } else { + *datap = arc_alloc_buf(os->os_spa, db, type, psize); + } + bcopy(db->db.db_data, (*datap)->b_data, psize); } db->db_data_pending = dr; From ad961313f3747aa5537454ba415ee202bebf70af Mon Sep 17 00:00:00 2001 From: Antonio Russo Date: Thu, 18 Mar 2021 18:05:54 -0600 Subject: [PATCH 3/3] Reinstate "Add zstd support to zfs" This commit reverts the partial reversion of 10b3c7f5e4, transposed to account for the un-consolidation of dbuf_alloc_arcbuf_from_arcbuf. Signed-off-by: Antonio Russo --- module/zfs/dbuf.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c index 304c353f2b32..93c404b57508 100644 --- a/module/zfs/dbuf.c +++ b/module/zfs/dbuf.c @@ -1543,6 +1543,7 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg) spa_t *spa = db->db_objset->os_spa; enum zio_compress compress_type = arc_get_compression(db->db_buf); + uint8_t complevel = arc_get_complevel(db->db_buf); if (arc_is_encrypted(db->db_buf)) { boolean_t byteorder; @@ -1555,11 +1556,12 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg) dr->dt.dl.dr_data = arc_alloc_raw_buf(spa, db, dmu_objset_id(dn->dn_objset), byteorder, salt, iv, mac, dn->dn_type, size, arc_buf_lsize(db->db_buf), - compress_type); + compress_type, complevel); } else if (compress_type != ZIO_COMPRESS_OFF) { ASSERT3U(type, ==, ARC_BUFC_DATA); dr->dt.dl.dr_data = arc_alloc_compressed_buf(spa, db, - size, arc_buf_lsize(db->db_buf), compress_type); + size, arc_buf_lsize(db->db_buf), compress_type, + complevel); } else { dr->dt.dl.dr_data = arc_alloc_buf(spa, db, type, size); } @@ -3366,6 +3368,7 @@ dbuf_hold_copy(dnode_t *dn, dmu_buf_impl_t *db) dbuf_dirty_record_t *dr = db->db_data_pending; arc_buf_t *data = dr->dt.dl.dr_data; enum zio_compress compress_type = arc_get_compression(data); + uint8_t complevel = arc_get_complevel(data); if (arc_is_encrypted(data)) { boolean_t byteorder; @@ -3377,11 +3380,11 @@ dbuf_hold_copy(dnode_t *dn, dmu_buf_impl_t *db) dbuf_set_data(db, arc_alloc_raw_buf(dn->dn_objset->os_spa, db, dmu_objset_id(dn->dn_objset), byteorder, salt, iv, mac, dn->dn_type, arc_buf_size(data), arc_buf_lsize(data), - compress_type)); + compress_type, complevel)); } else if (compress_type != ZIO_COMPRESS_OFF) { dbuf_set_data(db, arc_alloc_compressed_buf( dn->dn_objset->os_spa, db, arc_buf_size(data), - arc_buf_lsize(data), compress_type)); + arc_buf_lsize(data), compress_type, complevel)); } else { dbuf_set_data(db, arc_alloc_buf(dn->dn_objset->os_spa, db, DBUF_GET_BUFC_TYPE(db), db->db.db_size)); @@ -4312,6 +4315,7 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx) int lsize = arc_buf_lsize(*datap); arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); enum zio_compress compress_type = arc_get_compression(*datap); + uint8_t complevel = arc_get_complevel(*datap); if (arc_is_encrypted(*datap)) { boolean_t byteorder; @@ -4322,11 +4326,12 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx) arc_get_raw_params(*datap, &byteorder, salt, iv, mac); *datap = arc_alloc_raw_buf(os->os_spa, db, dmu_objset_id(os), byteorder, salt, iv, mac, - dn->dn_type, psize, lsize, compress_type); + dn->dn_type, psize, lsize, compress_type, + complevel); } else if (compress_type != ZIO_COMPRESS_OFF) { ASSERT3U(type, ==, ARC_BUFC_DATA); *datap = arc_alloc_compressed_buf(os->os_spa, db, - psize, lsize, compress_type); + psize, lsize, compress_type, complevel); } else { *datap = arc_alloc_buf(os->os_spa, db, type, psize); }