From bcd0430236c213520ff88a4e26734c2cfc30aaa5 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Tue, 10 Jun 2025 12:28:14 -0400 Subject: [PATCH] Allow zero compression if dedup is enabled Having high-refcount dedup entries for zero blocks is inefficient when they could be recorded as a holes instead. Normally, zero compression is not done if compression is disabled to not confuse naive benchmarks. But with dedup enabled, it is expected that the write will be skipped anyway, so we are just optimizing the way it is skipped. Reviewed-by: Rob Norris Reviewed-by: Brian Behlendorf Reviewed-by: George Melikov Signed-off-by: Alexander Motin Sponsored by: iXsystems, Inc. Closes #17435 --- module/zfs/dmu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/module/zfs/dmu.c b/module/zfs/dmu.c index 96ac2cc28..9a2dfe9b1 100644 --- a/module/zfs/dmu.c +++ b/module/zfs/dmu.c @@ -2422,6 +2422,15 @@ dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp) complevel = zio_complevel_select(os->os_spa, compress, complevel, complevel); + /* + * Storing many references to an all zeros block in the dedup + * table would be expensive. Instead, if dedup is enabled, + * store them as holes even if compression is not enabled. + */ + if (compress == ZIO_COMPRESS_OFF && + dedup_checksum != ZIO_CHECKSUM_OFF) + compress = ZIO_COMPRESS_EMPTY; + checksum = (dedup_checksum == ZIO_CHECKSUM_OFF) ? zio_checksum_select(dn->dn_checksum, checksum) : dedup_checksum;