zio_compress: introduce max size threshold

Now default compression is lz4, which can stop
compression process by itself on incompressible data.
If there are additional size checks -
we will only make our compressratio worse.

New usable compression thresholds are:
- less than BPE_PAYLOAD_SIZE (embedded_data feature);
- at least one saved sector.

Old 12.5% threshold is left to minimize affect
on existing user expectations of CPU utilization.

If data wasn't compressed - it will be saved as
ZIO_COMPRESS_OFF, so if we really need to recompress
data without ashift info and check anything -
we can just compress it with zero threshold.
So, we don't need a new feature flag here!

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: George Melikov <mail@gmelikov.ru>
Closes #9416
This commit is contained in:
George Melikov
2019-09-10 23:34:53 +03:00
committed by Brian Behlendorf
parent 4bf6a2ab87
commit 522f2629c8
8 changed files with 57 additions and 28 deletions
+20 -1
View File
@@ -26,6 +26,7 @@
* Copyright (c) 2019, 2023, 2024, Klara Inc.
* Copyright (c) 2019, Allan Jude
* Copyright (c) 2021, Datto, Inc.
* Copyright (c) 2021, 2024 by George Melikov. All rights reserved.
*/
#include <sys/sysmacros.h>
@@ -1704,6 +1705,21 @@ zio_roundup_alloc_size(spa_t *spa, uint64_t size)
return (spa->spa_min_alloc);
}
size_t
zio_get_compression_max_size(uint64_t gcd_alloc, uint64_t min_alloc,
size_t s_len)
{
size_t d_len;
/* minimum 12.5% must be saved (legacy value, may be changed later) */
d_len = s_len - (s_len >> 3);
d_len = d_len - d_len % gcd_alloc;
if (d_len < min_alloc)
return (BPE_PAYLOAD_SIZE);
return (d_len);
}
/*
* ==========================================================================
* Prepare to read and write logical blocks
@@ -1885,7 +1901,10 @@ zio_write_compress(zio_t *zio)
psize = lsize;
else
psize = zio_compress_data(compress, zio->io_abd, &cabd,
lsize, zp->zp_complevel);
lsize,
zio_get_compression_max_size(spa->spa_gcd_alloc,
spa->spa_min_alloc, lsize),
zp->zp_complevel);
if (psize == 0) {
compress = ZIO_COMPRESS_OFF;
} else if (psize >= lsize) {