From f9d66fb0df6d6d48a60762e8e18a0fc7ba4feb27 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 | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/sys/zio.h b/include/sys/zio.h index 1b58b5e66db2..b3aedaec1779 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -598,8 +598,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 30b7b191bb80..22d49ca307fc 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -10434,7 +10434,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 5cc9ab7901d2..cd81e2921f0c 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1677,8 +1677,8 @@ 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; @@ -1686,7 +1686,8 @@ zio_get_compression_max_size(uint64_t gcd_alloc, uint64_t min_alloc, d_len = s_len - (s_len >> 3); d_len = d_len - d_len % gcd_alloc; - if (d_len < min_alloc) + /* ZLE can't use exactly d_len bytes, it needs more, so ignore it */ + if (d_len < min_alloc && compress != ZIO_COMPRESS_ZLE) return (BPE_PAYLOAD_SIZE); return (d_len); } @@ -1867,7 +1868,7 @@ zio_write_compress(zio_t *zio) !(zio->io_flags & ZIO_FLAG_RAW_COMPRESS)) { void *cbuf = NULL; psize = zio_compress_data(compress, zio->io_abd, &cbuf, lsize, - zio_get_compression_max_size(spa->spa_gcd_alloc, + 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;