diff options
author | George Melikov <[email protected]> | 2019-09-10 23:34:53 +0300 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2024-09-19 17:23:58 -0700 |
commit | 522f2629c8ec39e3683c09969066a80ee90ccc04 (patch) | |
tree | bc93d284449665324868b939a518545a59f51141 /module | |
parent | 4bf6a2ab87c98efe1b010b403a991500d689112a (diff) |
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 <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: George Melikov <[email protected]>
Closes #9416
Diffstat (limited to 'module')
-rw-r--r-- | module/zfs/arc.c | 13 | ||||
-rw-r--r-- | module/zfs/dmu_recv.c | 2 | ||||
-rw-r--r-- | module/zfs/zio.c | 21 | ||||
-rw-r--r-- | module/zfs/zio_compress.c | 14 |
4 files changed, 32 insertions, 18 deletions
diff --git a/module/zfs/arc.c b/module/zfs/arc.c index b5bcd367b..8e513a4e6 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -29,6 +29,7 @@ * Copyright (c) 2019, 2023, Klara Inc. * Copyright (c) 2019, Allan Jude * Copyright (c) 2020, The FreeBSD Foundation [1] + * Copyright (c) 2021, 2024 by George Melikov. All rights reserved. * * [1] Portions of this software were developed by Allan Jude * under sponsorship from the FreeBSD Foundation. @@ -1786,7 +1787,7 @@ arc_hdr_authenticate(arc_buf_hdr_t *hdr, spa_t *spa, uint64_t dsobj) !HDR_COMPRESSION_ENABLED(hdr)) { abd = NULL; csize = zio_compress_data(HDR_GET_COMPRESS(hdr), - hdr->b_l1hdr.b_pabd, &abd, lsize, hdr->b_complevel); + hdr->b_l1hdr.b_pabd, &abd, lsize, lsize, hdr->b_complevel); ASSERT3P(abd, !=, NULL); ASSERT3U(csize, <=, psize); abd_zero_off(abd, csize, psize - csize); @@ -9029,8 +9030,8 @@ l2arc_apply_transforms(spa_t *spa, arc_buf_hdr_t *hdr, uint64_t asize, if (compress != ZIO_COMPRESS_OFF && !HDR_COMPRESSION_ENABLED(hdr)) { cabd = abd_alloc_for_io(MAX(size, asize), ismd); uint64_t csize = zio_compress_data(compress, to_write, &cabd, - size, hdr->b_complevel); - if (csize > psize) { + size, MIN(size, psize), hdr->b_complevel); + if (csize >= size || csize > psize) { /* * We can't re-compress the block into the original * psize. Even if it fits into asize, it does not @@ -10521,9 +10522,11 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb) */ list_insert_tail(&cb->l2wcb_abd_list, abd_buf); - /* try to compress the buffer */ + /* try to compress the buffer, at least one sector to save */ psize = zio_compress_data(ZIO_COMPRESS_LZ4, - abd_buf->abd, &abd, sizeof (*lb), 0); + abd_buf->abd, &abd, sizeof (*lb), + zio_get_compression_max_size(dev->l2ad_vdev->vdev_ashift, + dev->l2ad_vdev->vdev_ashift, sizeof (*lb)), 0); /* a log block is never entirely zero */ ASSERT(psize != 0); diff --git a/module/zfs/dmu_recv.c b/module/zfs/dmu_recv.c index a1752650f..9b3da032f 100644 --- a/module/zfs/dmu_recv.c +++ b/module/zfs/dmu_recv.c @@ -1408,7 +1408,7 @@ do_corrective_recv(struct receive_writer_arg *rwa, struct drr_write *drrw, abd_t *cabd = abd_alloc_linear(BP_GET_PSIZE(bp), B_FALSE); uint64_t csize = zio_compress_data(BP_GET_COMPRESS(bp), - abd, &cabd, abd_get_size(abd), + abd, &cabd, abd_get_size(abd), BP_GET_PSIZE(bp), rwa->os->os_complevel); abd_zero_off(cabd, csize, BP_GET_PSIZE(bp) - csize); /* Swap in newly compressed data into the abd */ diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 2e38d47c9..4ba926081 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -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) { diff --git a/module/zfs/zio_compress.c b/module/zfs/zio_compress.c index 9182917f7..10c482573 100644 --- a/module/zfs/zio_compress.c +++ b/module/zfs/zio_compress.c @@ -22,15 +22,11 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. - */ -/* * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. - */ - -/* * Copyright (c) 2013, 2018 by Delphix. All rights reserved. * Copyright (c) 2019, 2024, Klara, Inc. * Copyright (c) 2019, Allan Jude + * Copyright (c) 2021, 2024 by George Melikov. All rights reserved. */ #include <sys/zfs_context.h> @@ -129,9 +125,9 @@ zio_compress_select(spa_t *spa, enum zio_compress child, size_t zio_compress_data(enum zio_compress c, abd_t *src, abd_t **dst, size_t s_len, - uint8_t level) + size_t d_len, uint8_t level) { - size_t c_len, d_len; + size_t c_len; uint8_t complevel; zio_compress_info_t *ci = &zio_compress_table[c]; @@ -156,15 +152,11 @@ zio_compress_data(enum zio_compress c, abd_t *src, abd_t **dst, size_t s_len, if (*dst == NULL) *dst = abd_alloc_sametype(src, s_len); - /* Compress at least 12.5%, but limit to the size of the dest abd. */ - d_len = MIN(s_len - (s_len >> 3), abd_get_size(*dst)); - c_len = ci->ci_compress(src, *dst, s_len, d_len, complevel); if (c_len > d_len) return (s_len); - ASSERT3U(c_len, <=, d_len); return (c_len); } |