Skip to content

Commit 1f6f9b4

Browse files
committed
Enable zero-elimination if dedup is activated
Creating high-refcount dedup entries for checksums of each record size is inefficient when the record could be recorded as a hole instead. Normally, zero-elimination is disabled if compression is not enabled, but in the dedup case, it is expected that the write will be skipped anyway, we are just optimizing the way the write is skipped. Signed-off-by: Allan Jude <[email protected]>
1 parent aa46cc9 commit 1f6f9b4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

module/zfs/zio.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@ zio_write_compress(zio_t *zio)
19321932
spa_t *spa = zio->io_spa;
19331933
zio_prop_t *zp = &zio->io_prop;
19341934
enum zio_compress compress = zp->zp_compress;
1935+
boolean_t dedup = zp->zp_dedup;
19351936
blkptr_t *bp = zio->io_bp;
19361937
uint64_t lsize = zio->io_lsize;
19371938
uint64_t psize = zio->io_size;
@@ -2087,6 +2088,21 @@ zio_write_compress(zio_t *zio)
20872088
zio_push_transform(zio, cdata,
20882089
psize, rounded, NULL);
20892090
}
2091+
} else if (dedup == B_TRUE) {
2092+
/*
2093+
* Storing many references to an all zeros block in the dedup
2094+
* table would be expensive, and each different size of block
2095+
* would have its own checksum.
2096+
* Instead, if dedup is enabled, store all zero blocks as
2097+
* holes even if compression is not enabled.
2098+
*/
2099+
if (abd_cmp_zero(zio->io_abd, lsize) == 0) {
2100+
psize = 0;
2101+
compress = ZIO_COMPRESS_OFF;
2102+
dedup = B_FALSE;
2103+
} else {
2104+
psize = lsize;
2105+
}
20902106
} else {
20912107
ASSERT3U(psize, !=, 0);
20922108
}
@@ -2129,7 +2145,7 @@ zio_write_compress(zio_t *zio)
21292145
BP_SET_PSIZE(bp, psize);
21302146
BP_SET_COMPRESS(bp, compress);
21312147
BP_SET_CHECKSUM(bp, zp->zp_checksum);
2132-
BP_SET_DEDUP(bp, zp->zp_dedup);
2148+
BP_SET_DEDUP(bp, dedup);
21332149
BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
21342150
if (zp->zp_dedup) {
21352151
ASSERT(zio->io_child_type == ZIO_CHILD_LOGICAL);

0 commit comments

Comments
 (0)