Skip to content

Commit

Permalink
ZLE compression: don't use BPE_PAYLOAD_SIZE
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
gmelikov committed Sep 19, 2024
1 parent 3433c80 commit caa6588
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
13 changes: 9 additions & 4 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit caa6588

Please sign in to comment.