Skip to content

Commit

Permalink
zio_compress_data: add 'check_ratio' arg
Browse files Browse the repository at this point in the history
If data was compressed and passed ratio
checks before - we can skip these checks
for reproducible results.

Signed-off-by: George Melikov <[email protected]>
  • Loading branch information
gmelikov committed Oct 21, 2019
1 parent 6e53663 commit 10488d9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/sys/zio_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extern int lz4_decompress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
* Compress and decompress data if necessary.
*/
extern size_t zio_compress_data(enum zio_compress c, abd_t *src, void *dst,
size_t s_len);
size_t s_len, boolean_t check_ratio);
extern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
size_t s_len, size_t d_len);
extern int zio_decompress_data_buf(enum zio_compress c, void *src, void *dst,
Expand Down
5 changes: 3 additions & 2 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ arc_hdr_authenticate(arc_buf_hdr_t *hdr, spa_t *spa, uint64_t dsobj)
abd_take_ownership_of_buf(abd, B_TRUE);

csize = zio_compress_data(HDR_GET_COMPRESS(hdr),
hdr->b_l1hdr.b_pabd, tmpbuf, lsize);
hdr->b_l1hdr.b_pabd, tmpbuf, lsize, B_FALSE);
ASSERT3U(csize, <=, psize);
abd_zero_off(abd, csize, psize - csize);
}
Expand Down Expand Up @@ -8530,7 +8530,8 @@ l2arc_apply_transforms(spa_t *spa, arc_buf_hdr_t *hdr, uint64_t asize,
cabd = abd_alloc_for_io(asize, ismd);
tmp = abd_borrow_buf(cabd, asize);

psize = zio_compress_data(compress, to_write, tmp, size);
psize = zio_compress_data(compress, to_write, tmp, size,
B_FALSE);
ASSERT3U(psize, <=, HDR_GET_PSIZE(hdr));
if (psize < asize)
bzero((char *)tmp + psize, asize - psize);
Expand Down
5 changes: 3 additions & 2 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,8 @@ zio_write_compress(zio_t *zio)
if (compress != ZIO_COMPRESS_OFF &&
!(zio->io_flags & ZIO_FLAG_RAW_COMPRESS)) {
void *cbuf = zio_buf_alloc(lsize);
psize = zio_compress_data(compress, zio->io_abd, cbuf, lsize);
psize = zio_compress_data(compress, zio->io_abd, cbuf, lsize,
B_TRUE);
if (psize == 0 || psize == lsize) {
compress = ZIO_COMPRESS_OFF;
zio_buf_free(cbuf, lsize);
Expand Down Expand Up @@ -1670,7 +1671,7 @@ zio_write_compress(zio_t *zio)
* to a hole.
*/
psize = zio_compress_data(ZIO_COMPRESS_EMPTY,
zio->io_abd, NULL, lsize);
zio->io_abd, NULL, lsize, B_FALSE);
if (psize == 0)
compress = ZIO_COMPRESS_OFF;
} else {
Expand Down
26 changes: 19 additions & 7 deletions module/zfs/zio_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ 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,
boolean_t check_ratio)
{
size_t c_len, d_len;
zio_compress_info_t *ci = &zio_compress_table[c];
Expand All @@ -119,12 +120,23 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
if (c == ZIO_COMPRESS_EMPTY)
return (s_len);

/* Data is already less or equal to compress threshold */
if (s_len <= zfs_compress_threshold_bytes)
return (s_len);

/* Write compressed only if there is at least one sector compressed */
d_len = s_len - MIN(s_len, zfs_compress_threshold_bytes);
/*
* If data was compressed and passed ratio checks before -
* we can skip these checks for reproducible results.
*/
if (check_ratio) {
/* Data is already less or equal to compress threshold */
if (s_len <= zfs_compress_threshold_bytes)
return (s_len);

/*
* Write compressed only if there is at least
* one sector compressed
*/
d_len = s_len - MIN(s_len, zfs_compress_threshold_bytes);
} else {
d_len = s_len;
}

/* No compression algorithms can read from ABDs directly */
void *tmp = abd_borrow_buf_copy(src, s_len);
Expand Down

0 comments on commit 10488d9

Please sign in to comment.