Skip to content

Commit b7b44a6

Browse files
committed
zio: make io_bp_orig a separate allocation
We only need a copy if we would modify the original and might need to revert, which only applies to non-vdev writes. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Signed-off-by: Rob Norris <[email protected]>
1 parent 32e8a43 commit b7b44a6

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

include/sys/zio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ struct zio {
498498
zio_done_func_t *io_done;
499499
void *io_private;
500500
int64_t io_prev_space_delta; /* DMU private */
501-
blkptr_t io_bp_orig;
501+
blkptr_t *io_bp_orig;
502502
/* io_lsize != io_orig_size iff this is a raw write */
503503
uint64_t io_lsize;
504504

module/zfs/arc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,7 +6985,7 @@ arc_write_done(zio_t *zio)
69856985
* buffers from the hash table when we arc_free().
69866986
*/
69876987
if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {
6988-
if (!BP_EQUAL(&zio->io_bp_orig, zio->io_bp))
6988+
if (!BP_EQUAL(zio->io_bp_orig, zio->io_bp))
69896989
panic("bad overwrite, hdr=%p exists=%p",
69906990
(void *)hdr, (void *)exists);
69916991
ASSERT(zfs_refcount_is_zero(
@@ -6998,7 +6998,7 @@ arc_write_done(zio_t *zio)
69986998
} else if (zio->io_flags & ZIO_FLAG_NOPWRITE) {
69996999
/* nopwrite */
70007000
ASSERT(zio->io_prop.zp_nopwrite);
7001-
if (!BP_EQUAL(&zio->io_bp_orig, zio->io_bp))
7001+
if (!BP_EQUAL(zio->io_bp_orig, zio->io_bp))
70027002
panic("bad nopwrite, hdr=%p exists=%p",
70037003
(void *)hdr, (void *)exists);
70047004
} else {

module/zfs/dbuf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,10 +4667,10 @@ dbuf_lightweight_done(zio_t *zio)
46674667
dmu_tx_t *tx = os->os_synctx;
46684668

46694669
if (zio->io_flags & (ZIO_FLAG_IO_REWRITE | ZIO_FLAG_NOPWRITE)) {
4670-
ASSERT(BP_EQUAL(zio->io_bp, &zio->io_bp_orig));
4670+
ASSERT(BP_EQUAL(zio->io_bp, zio->io_bp_orig));
46714671
} else {
46724672
dsl_dataset_t *ds = os->os_dsl_dataset;
4673-
(void) dsl_dataset_block_kill(ds, &zio->io_bp_orig, tx, B_TRUE);
4673+
(void) dsl_dataset_block_kill(ds, zio->io_bp_orig, tx, B_TRUE);
46744674
dsl_dataset_block_born(ds, zio->io_bp, tx);
46754675
}
46764676

@@ -4929,7 +4929,7 @@ dbuf_write_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
49294929
dmu_buf_impl_t *db = vdb;
49304930
dnode_t *dn;
49314931
blkptr_t *bp = zio->io_bp;
4932-
blkptr_t *bp_orig = &zio->io_bp_orig;
4932+
blkptr_t *bp_orig = zio->io_bp_orig;
49334933
spa_t *spa = zio->io_spa;
49344934
int64_t delta;
49354935
uint64_t fill = 0;
@@ -5077,7 +5077,7 @@ dbuf_write_done(zio_t *zio, arc_buf_t *buf, void *vdb)
50775077
{
50785078
(void) buf;
50795079
dmu_buf_impl_t *db = vdb;
5080-
blkptr_t *bp_orig = &zio->io_bp_orig;
5080+
blkptr_t *bp_orig = zio->io_bp_orig;
50815081
blkptr_t *bp = db->db_blkptr;
50825082
objset_t *os = db->db_objset;
50835083
dmu_tx_t *tx = os->os_synctx;

module/zfs/dmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ dmu_sync_done(zio_t *zio, arc_buf_t *buf, void *varg)
19081908
dr->dt.dl.dr_nopwrite = !!(zio->io_flags & ZIO_FLAG_NOPWRITE);
19091909
if (dr->dt.dl.dr_nopwrite) {
19101910
blkptr_t *bp = zio->io_bp;
1911-
blkptr_t *bp_orig = &zio->io_bp_orig;
1911+
blkptr_t *bp_orig = zio->io_bp_orig;
19121912
uint8_t chksum = BP_GET_CHECKSUM(bp_orig);
19131913

19141914
ASSERT(BP_EQUAL(bp, bp_orig));
@@ -1963,7 +1963,7 @@ dmu_sync_late_arrival_done(zio_t *zio)
19631963
zil_lwb_add_block(zgd->zgd_lwb, zgd->zgd_bp);
19641964

19651965
if (!BP_IS_HOLE(bp)) {
1966-
blkptr_t *bp_orig __maybe_unused = &zio->io_bp_orig;
1966+
blkptr_t *bp_orig __maybe_unused = zio->io_bp_orig;
19671967
ASSERT(!(zio->io_flags & ZIO_FLAG_NOPWRITE));
19681968
ASSERT(BP_IS_HOLE(bp_orig) || !BP_EQUAL(bp, bp_orig));
19691969
ASSERT(BP_GET_BIRTH(zio->io_bp) == zio->io_txg);

module/zfs/dmu_objset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ dmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg)
15281528
{
15291529
(void) abuf;
15301530
blkptr_t *bp = zio->io_bp;
1531-
blkptr_t *bp_orig = &zio->io_bp_orig;
1531+
blkptr_t *bp_orig = zio->io_bp_orig;
15321532
objset_t *os = arg;
15331533

15341534
if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {

module/zfs/zio.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,10 @@ zio_create(zio_t *pio, spa_t *spa, uint64_t txg, const blkptr_t *bp,
10051005
} else {
10061006
zio->io_bp = (blkptr_t *)bp;
10071007
}
1008-
zio->io_bp_orig = *bp;
1008+
if (type == ZIO_TYPE_WRITE &&
1009+
zio->io_child_type != ZIO_CHILD_VDEV) {
1010+
zio->io_bp_orig = zio_dup_bp(bp);
1011+
}
10091012
if (zio->io_child_type == ZIO_CHILD_LOGICAL)
10101013
zio->io_logical = zio;
10111014
if (zio->io_child_type > ZIO_CHILD_GANG && BP_IS_GANG(bp))
@@ -1064,6 +1067,8 @@ zio_destroy(zio_t *zio)
10641067
cv_destroy(&zio->io_cv);
10651068
if (zio->io_bp_copy != NULL)
10661069
kmem_cache_free(zio_bp_cache, zio->io_bp_copy);
1070+
if (zio->io_bp_orig != NULL)
1071+
kmem_cache_free(zio_bp_cache, zio->io_bp_orig);
10671072
kmem_cache_free(zio_cache, zio);
10681073
}
10691074

@@ -1931,7 +1936,7 @@ zio_write_bp_init(zio_t *zio)
19311936
* it as a regular write I/O.
19321937
*/
19331938
zio->io_bp_override = NULL;
1934-
*bp = zio->io_bp_orig;
1939+
*bp = *zio->io_bp_orig;
19351940
zio->io_pipeline = zio->io_orig_pipeline;
19361941
}
19371942

@@ -2063,7 +2068,7 @@ zio_write_compress(zio_t *zio)
20632068
* it as a regular write I/O.
20642069
*/
20652070
zio->io_bp_override = NULL;
2066-
*bp = zio->io_bp_orig;
2071+
*bp = *zio->io_bp_orig;
20672072
zio->io_pipeline = zio->io_orig_pipeline;
20682073

20692074
} else if ((zio->io_flags & ZIO_FLAG_RAW_ENCRYPT) != 0 &&
@@ -2125,7 +2130,7 @@ zio_write_compress(zio_t *zio)
21252130
}
21262131

21272132
if (psize == 0) {
2128-
if (BP_GET_LOGICAL_BIRTH(&zio->io_bp_orig) != 0 &&
2133+
if (BP_GET_LOGICAL_BIRTH(zio->io_bp_orig) != 0 &&
21292134
spa_feature_is_active(spa, SPA_FEATURE_HOLE_BIRTH)) {
21302135
BP_SET_LSIZE(bp, lsize);
21312136
BP_SET_TYPE(bp, zp->zp_type);
@@ -3140,7 +3145,7 @@ zio_write_gang_member_ready(zio_t *zio)
31403145
* If we're getting direct-invoked from zio_write_gang_block(),
31413146
* the bp_orig will be set.
31423147
*/
3143-
ASSERT(BP_IS_HOLE(&zio->io_bp_orig) ||
3148+
ASSERT(BP_IS_HOLE(zio->io_bp_orig) ||
31443149
zio->io_flags & ZIO_FLAG_PREALLOCATED);
31453150

31463151
ASSERT(zio->io_child_type == ZIO_CHILD_GANG);
@@ -3320,7 +3325,7 @@ zio_write_gang_block(zio_t *pio, metaslab_class_t *mc)
33203325
if (allocated) {
33213326
metaslab_trace_move(&cio_list, &cio->io_alloc_list);
33223327
metaslab_group_alloc_increment_all(spa,
3323-
&cio->io_bp_orig, zio->io_allocator, flags, psize,
3328+
cio->io_bp_orig, zio->io_allocator, flags, psize,
33243329
cio);
33253330
}
33263331
/*
@@ -3389,7 +3394,7 @@ static zio_t *
33893394
zio_nop_write(zio_t *zio)
33903395
{
33913396
blkptr_t *bp = zio->io_bp;
3392-
blkptr_t *bp_orig = &zio->io_bp_orig;
3397+
blkptr_t *bp_orig = zio->io_bp_orig;
33933398
zio_prop_t *zp = &zio->io_prop;
33943399

33953400
ASSERT(BP_IS_HOLE(bp));
@@ -3961,9 +3966,9 @@ zio_ddt_write(zio_t *zio)
39613966
*/
39623967
if (zp->zp_rewrite) {
39633968
uint64_t orig_logical_birth =
3964-
BP_GET_LOGICAL_BIRTH(&zio->io_bp_orig);
3969+
BP_GET_LOGICAL_BIRTH(zio->io_bp_orig);
39653970
ddt_bp_fill(ddp, v, bp, orig_logical_birth);
3966-
if (BP_EQUAL(bp, &zio->io_bp_orig)) {
3971+
if (BP_EQUAL(bp, zio->io_bp_orig)) {
39673972
/* We can skip accounting. */
39683973
zio->io_flags |= ZIO_FLAG_NOPWRITE;
39693974
ddt_exit(ddt);
@@ -4271,12 +4276,12 @@ zio_dva_allocate(zio_t *zio)
42714276
}
42724277
if (zio->io_flags & ZIO_FLAG_PREALLOCATED) {
42734278
ASSERT3U(zio->io_child_type, ==, ZIO_CHILD_GANG);
4274-
memcpy(zio->io_bp->blk_dva, zio->io_bp_orig.blk_dva,
4279+
memcpy(zio->io_bp->blk_dva, zio->io_bp_orig->blk_dva,
42754280
3 * sizeof (dva_t));
42764281
BP_SET_LOGICAL_BIRTH(zio->io_bp,
4277-
BP_GET_LOGICAL_BIRTH(&zio->io_bp_orig));
4282+
BP_GET_LOGICAL_BIRTH(zio->io_bp_orig));
42784283
BP_SET_PHYSICAL_BIRTH(zio->io_bp,
4279-
BP_GET_RAW_PHYSICAL_BIRTH(&zio->io_bp_orig));
4284+
BP_GET_RAW_PHYSICAL_BIRTH(zio->io_bp_orig));
42804285
return (zio);
42814286
}
42824287

@@ -4408,7 +4413,7 @@ zio_dva_allocate(zio_t *zio)
44084413
* For rewrite operations, preserve the logical birth time
44094414
* but set the physical birth time to the current txg.
44104415
*/
4411-
uint64_t logical_birth = BP_GET_LOGICAL_BIRTH(&zio->io_bp_orig);
4416+
uint64_t logical_birth = BP_GET_LOGICAL_BIRTH(zio->io_bp_orig);
44124417
ASSERT3U(logical_birth, <=, zio->io_txg);
44134418
BP_SET_BIRTH(zio->io_bp, logical_birth, zio->io_txg);
44144419
BP_SET_REWRITE(zio->io_bp, 1);
@@ -5512,7 +5517,7 @@ zio_done(zio_t *zio)
55125517
BP_GET_NDVAS(zio->io_bp)));
55135518
}
55145519
if (zio->io_flags & ZIO_FLAG_NOPWRITE)
5515-
VERIFY(BP_EQUAL(zio->io_bp, &zio->io_bp_orig));
5520+
VERIFY(BP_EQUAL(zio->io_bp, zio->io_bp_orig));
55165521
}
55175522

55185523
/*

0 commit comments

Comments
 (0)