From de4a0c31b5d269e39114181465ddbba448a4db3f Mon Sep 17 00:00:00 2001 From: "Robert W. Brewer" Date: Tue, 24 Apr 2018 22:16:23 -0400 Subject: [PATCH] initial compression heuristic --- module/zfs/zio_compress.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/module/zfs/zio_compress.c b/module/zfs/zio_compress.c index 974af03d12c6..e6340bb5cf51 100644 --- a/module/zfs/zio_compress.c +++ b/module/zfs/zio_compress.c @@ -115,11 +115,28 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len) if (c == ZIO_COMPRESS_EMPTY) return (s_len); + /* No compression algorithms can read from ABDs directly */ + void *tmp = abd_borrow_buf_copy(src, s_len); + + /* for gzip 6+, use lz4 as a heuristic for compressibility */ + if (ci->ci_compress == gzip_compress && ci->ci_level >= 6) { + /* lz4 must find some compression */ + if (s_len) { + d_len = s_len - 1; + } else { + d_len = s_len; + } + + c_len = lz4_compress_zfs(tmp, dst, s_len, d_len, 0); + if (c_len > d_len) { + abd_return_buf(src, tmp, s_len); + return (s_len); + } + } + /* Compress at least 12.5% */ d_len = s_len - (s_len >> 3); - /* No compression algorithms can read from ABDs directly */ - void *tmp = abd_borrow_buf_copy(src, s_len); c_len = ci->ci_compress(tmp, dst, s_len, d_len, ci->ci_level); abd_return_buf(src, tmp, s_len);