Skip memory allocation when compressing holes

Hole detection in the zio compression code allows us to
opportunistically skip compression on holes. We can go a step further
by not doing memory allocations on holes either.

Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Richard Yao <richard.yao@klarasystems.com>
Sponsored-by: Wasabi Technology, Inc.
Closes #14500
This commit is contained in:
Richard Yao
2023-02-27 17:41:02 -05:00
committed by GitHub
parent f58e513f74
commit bff26b0220
5 changed files with 23 additions and 16 deletions
+5 -2
View File
@@ -125,7 +125,7 @@ zio_compress_zeroed_cb(void *data, size_t len, void *private)
}
size_t
zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len,
zio_compress_data(enum zio_compress c, abd_t *src, void **dst, size_t s_len,
uint8_t level)
{
size_t c_len, d_len;
@@ -163,9 +163,12 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len,
ASSERT3U(complevel, !=, ZIO_COMPLEVEL_INHERIT);
}
if (*dst == NULL)
*dst = zio_buf_alloc(s_len);
/* 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, complevel);
c_len = ci->ci_compress(tmp, *dst, s_len, d_len, complevel);
abd_return_buf(src, tmp, s_len);
if (c_len > d_len)