From 6789fa843623ef1614520b2dcd374bc827bf1a26 Mon Sep 17 00:00:00 2001 From: George Melikov Date: Wed, 29 May 2024 23:50:25 +0300 Subject: [PATCH] ZLE compression: don't use BPE_PAYLOAD_SIZE ZLE compressor needs additional bytes to process d_len argument efficiently. Don't use BPE_PAYLOAD_SIZE as d_len with it before we rework zle compressor somehow. Reviewed-by: Brian Behlendorf Reviewed-by: Tony Hutter Reviewed-by: Alexander Motin Signed-off-by: George Melikov Closes #9416 --- include/sys/zio.h | 4 ++-- module/zfs/arc.c | 3 ++- module/zfs/zio.c | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/sys/zio.h b/include/sys/zio.h index 9e3b66dc01db..f9409433e031 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -604,8 +604,8 @@ extern int zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg, extern void zio_flush(zio_t *zio, vdev_t *vd); extern void zio_shrink(zio_t *zio, uint64_t size); -extern size_t zio_get_compression_max_size(uint64_t gcd_alloc, - uint64_t min_alloc, size_t s_len); +extern size_t zio_get_compression_max_size(enum zio_compress compress, + uint64_t gcd_alloc, uint64_t min_alloc, size_t s_len); extern int zio_wait(zio_t *zio); extern void zio_nowait(zio_t *zio); extern void zio_execute(void *zio); diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 8e513a4e60fd..c222fd4287ec 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -10525,7 +10525,8 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb) /* try to compress the buffer, at least one sector to save */ psize = zio_compress_data(ZIO_COMPRESS_LZ4, abd_buf->abd, &abd, sizeof (*lb), - zio_get_compression_max_size(dev->l2ad_vdev->vdev_ashift, + zio_get_compression_max_size(ZIO_COMPRESS_LZ4, + dev->l2ad_vdev->vdev_ashift, dev->l2ad_vdev->vdev_ashift, sizeof (*lb)), 0); /* a log block is never entirely zero */ diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 4ba9260819c5..b26f5e80abfb 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1706,15 +1706,20 @@ zio_roundup_alloc_size(spa_t *spa, uint64_t size) } size_t -zio_get_compression_max_size(uint64_t gcd_alloc, uint64_t min_alloc, - size_t s_len) +zio_get_compression_max_size(enum zio_compress compress, 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); + /* ZLE can't use exactly d_len bytes, it needs more, so ignore it */ + if (compress == ZIO_COMPRESS_ZLE) + return (d_len); + d_len = d_len - d_len % gcd_alloc; + if (d_len < min_alloc) return (BPE_PAYLOAD_SIZE); return (d_len); @@ -1902,8 +1907,8 @@ zio_write_compress(zio_t *zio) else psize = zio_compress_data(compress, zio->io_abd, &cabd, lsize, - zio_get_compression_max_size(spa->spa_gcd_alloc, - spa->spa_min_alloc, lsize), + zio_get_compression_max_size(compress, + spa->spa_gcd_alloc, spa->spa_min_alloc, lsize), zp->zp_complevel); if (psize == 0) { compress = ZIO_COMPRESS_OFF;