From 9621596faabb626b853c813d7d6cd620401866ae 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. Signed-off-by: George Melikov --- 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 c372ee4bd3ce..bae0c833a173 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -599,8 +599,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 1387133b82e6..2a4f03b43255 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -10530,7 +10530,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, (void **) &tmpbuf, 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 2e8845ba41ce..61510c8f319a 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1686,15 +1686,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); @@ -1882,8 +1887,8 @@ zio_write_compress(zio_t *zio) else psize = zio_compress_data(compress, zio->io_abd, &cbuf, 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;