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 <robn@despairlabs.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by:	Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes #17435
This commit is contained in:
Alexander Motin 2025-06-10 12:28:14 -04:00 committed by GitHub
parent 0e9e2e2501
commit bcd0430236
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;