Skip to content

Commit 39d1434

Browse files
gmelikovgmelikov-mcs
authored andcommitted
zio_compress_data: add 'check_ratio' arg
If data was compressed and passed ratio checks before - we can skip these checks for reproducible results. Signed-off-by: George Melikov <[email protected]>
1 parent dc579e7 commit 39d1434

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

include/sys/zio_compress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extern int lz4_decompress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
110110
* Compress and decompress data if necessary.
111111
*/
112112
extern size_t zio_compress_data(enum zio_compress c, abd_t *src, void *dst,
113-
size_t s_len);
113+
size_t s_len, boolean_t check_ratio);
114114
extern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
115115
size_t s_len, size_t d_len);
116116
extern int zio_decompress_data_buf(enum zio_compress c, void *src, void *dst,

module/zfs/arc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ arc_hdr_authenticate(arc_buf_hdr_t *hdr, spa_t *spa, uint64_t dsobj)
16291629
abd_take_ownership_of_buf(abd, B_TRUE);
16301630

16311631
csize = zio_compress_data(HDR_GET_COMPRESS(hdr),
1632-
hdr->b_l1hdr.b_pabd, tmpbuf, lsize);
1632+
hdr->b_l1hdr.b_pabd, tmpbuf, lsize, B_FALSE);
16331633
ASSERT3U(csize, <=, psize);
16341634
abd_zero_off(abd, csize, psize - csize);
16351635
}
@@ -8113,7 +8113,8 @@ l2arc_apply_transforms(spa_t *spa, arc_buf_hdr_t *hdr, uint64_t asize,
81138113
cabd = abd_alloc_for_io(asize, ismd);
81148114
tmp = abd_borrow_buf(cabd, asize);
81158115

8116-
psize = zio_compress_data(compress, to_write, tmp, size);
8116+
psize = zio_compress_data(compress, to_write, tmp, size,
8117+
B_FALSE);
81178118
ASSERT3U(psize, <=, HDR_GET_PSIZE(hdr));
81188119
if (psize < asize)
81198120
bzero((char *)tmp + psize, asize - psize);

module/zfs/zio.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,8 @@ zio_write_compress(zio_t *zio)
16071607
if (compress != ZIO_COMPRESS_OFF &&
16081608
!(zio->io_flags & ZIO_FLAG_RAW_COMPRESS)) {
16091609
void *cbuf = zio_buf_alloc(lsize);
1610-
psize = zio_compress_data(compress, zio->io_abd, cbuf, lsize);
1610+
psize = zio_compress_data(compress, zio->io_abd, cbuf, lsize,
1611+
B_TRUE);
16111612
if (psize == 0 || psize == lsize) {
16121613
compress = ZIO_COMPRESS_OFF;
16131614
zio_buf_free(cbuf, lsize);
@@ -1670,7 +1671,7 @@ zio_write_compress(zio_t *zio)
16701671
* to a hole.
16711672
*/
16721673
psize = zio_compress_data(ZIO_COMPRESS_EMPTY,
1673-
zio->io_abd, NULL, lsize);
1674+
zio->io_abd, NULL, lsize, B_FALSE);
16741675
if (psize == 0)
16751676
compress = ZIO_COMPRESS_OFF;
16761677
} else {

module/zfs/zio_compress.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ zio_compress_zeroed_cb(void *data, size_t len, void *private)
101101
}
102102

103103
size_t
104-
zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
104+
zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len,
105+
boolean_t check_ratio)
105106
{
106107
size_t c_len, d_len;
107108
zio_compress_info_t *ci = &zio_compress_table[c];
@@ -119,12 +120,23 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
119120
if (c == ZIO_COMPRESS_EMPTY)
120121
return (s_len);
121122

122-
/* Data is already less or equal to compress threshold */
123-
if (s_len <= zfs_compress_threshold_bytes)
124-
return (s_len);
125-
126-
/* Write compressed only if there is at least one sector compressed */
127-
d_len = s_len - MIN(s_len, zfs_compress_threshold_bytes);
123+
/*
124+
* If data was compressed and passed ratio checks before -
125+
* we can skip these checks for reproducible results.
126+
*/
127+
if (check_ratio) {
128+
/* Data is already less or equal to compress threshold */
129+
if (s_len <= zfs_compress_threshold_bytes)
130+
return (s_len);
131+
132+
/*
133+
* Write compressed only if there is at least
134+
* one sector compressed
135+
*/
136+
d_len = s_len - MIN(s_len, zfs_compress_threshold_bytes);
137+
} else {
138+
d_len = s_len;
139+
}
128140

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

0 commit comments

Comments
 (0)