Skip to content

Commit e94ca35

Browse files
committed
zio_compress: use spa_max_ashift as threshold
Now default compression is lz4, which can stop compression process by itself on incompressible data. If there is additional size checks - we will only make our compressratio worse. So we can check only for sector size. If data wasn't compressed - it will be saved as ZIO_COMPRESS_OFF, so if we really need to recompress data without ashift info and check anything - we can just compress it with zero threshold. So, we don't need a new feature flag here! Signed-off-by: George Melikov <[email protected]>
1 parent a36bad1 commit e94ca35

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

include/sys/zio_compress.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2424
* Use is subject to license terms.
2525
* Copyright (c) 2015, 2016 by Delphix. All rights reserved.
26+
* Copyright (c) 2020 by George Melikov. All rights reserved.
2627
*/
2728

2829
#ifndef _SYS_ZIO_COMPRESS_H
@@ -110,7 +111,7 @@ extern int lz4_decompress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
110111
* Compress and decompress data if necessary.
111112
*/
112113
extern size_t zio_compress_data(enum zio_compress c, abd_t *src, void *dst,
113-
size_t s_len);
114+
size_t s_len, int compress_threshold);
114115
extern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
115116
size_t s_len, size_t d_len);
116117
extern int zio_decompress_data_buf(enum zio_compress c, void *src, void *dst,

man/man5/zfs-module-parameters.5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Default value: \fB16,777,216\fR (16MB)
408408
.RS 12n
409409
If we are not searching forward (due to metaslab_df_max_search,
410410
metaslab_df_free_pct, or metaslab_df_alloc_threshold), this tunable controls
411-
what segment is used. If it is set, we will use the largest free segment.
411+
what segment is used. If it is set, we will use the largest free segment.
412412
If it is not set, we will use a segment of exactly the requested size (or
413413
larger).
414414
.sp
@@ -3103,7 +3103,7 @@ Default value: \fB25\fR.
31033103
\fBzfs_sync_pass_dont_compress\fR (int)
31043104
.ad
31053105
.RS 12n
3106-
Starting in this sync pass, we disable compression (including of metadata).
3106+
Starting in this sync pass, we disable compression (including of metadata).
31073107
With the default setting, in practice, we don't have this many sync passes,
31083108
so this has no effect.
31093109
.sp

man/man8/zfsprops.8

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,11 @@ is selected, compression will explicitly check for blocks consisting of only
855855
zeroes (the NUL byte). When a zero-filled block is detected, it is stored as
856856
a hole and not compressed using the indicated compression algorithm.
857857
.Pp
858-
Any block being compressed must be no larger than 7/8 of its original size
859-
after compression, otherwise the compression will not be considered worthwhile
860-
and the block saved uncompressed. Note that when the logical block is less than
861-
8 times the disk sector size this effectively reduces the necessary compression
862-
ratio; for example 8k blocks on disks with 4k disk sectors must compress to 1/2
858+
Block must be compressed by at least max ashift of pool vdevs, otherwise
859+
the compression will not be considered worthwhile and the block saved
860+
uncompressed. Note that when the logical block is less than 8 times the disk
861+
sector size this effectively reduces the necessary compression ratio;
862+
for example 8k blocks on disks with 4k disk sectors must compress to 1/2
863863
or less of their original size.
864864
.It Xo
865865
.Sy context Ns = Ns Sy none Ns | Ns

module/zfs/arc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Copyright (c) 2017, Nexenta Systems, Inc. All rights reserved.
2727
* Copyright (c) 2019, loli10K <[email protected]>. All rights reserved.
2828
* Copyright (c) 2020, George Amanakis. All rights reserved.
29+
* Copyright (c) 2020 by George Melikov. All rights reserved.
2930
*/
3031

3132
/*
@@ -1755,7 +1756,7 @@ arc_hdr_authenticate(arc_buf_hdr_t *hdr, spa_t *spa, uint64_t dsobj)
17551756
abd_take_ownership_of_buf(abd, B_TRUE);
17561757

17571758
csize = zio_compress_data(HDR_GET_COMPRESS(hdr),
1758-
hdr->b_l1hdr.b_pabd, tmpbuf, lsize);
1759+
hdr->b_l1hdr.b_pabd, tmpbuf, lsize, 0);
17591760
ASSERT3U(csize, <=, psize);
17601761
abd_zero_off(abd, csize, psize - csize);
17611762
}
@@ -8531,7 +8532,8 @@ l2arc_apply_transforms(spa_t *spa, arc_buf_hdr_t *hdr, uint64_t asize,
85318532
cabd = abd_alloc_for_io(asize, ismd);
85328533
tmp = abd_borrow_buf(cabd, asize);
85338534

8534-
psize = zio_compress_data(compress, to_write, tmp, size);
8535+
psize = zio_compress_data(compress, to_write, tmp, size,
8536+
spa->spa_max_ashift);
85358537
ASSERT3U(psize, <=, HDR_GET_PSIZE(hdr));
85368538
if (psize < asize)
85378539
bzero((char *)tmp + psize, asize - psize);
@@ -9899,7 +9901,7 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb)
98999901
/* try to compress the buffer */
99009902
list_insert_tail(&cb->l2wcb_abd_list, abd_buf);
99019903
psize = zio_compress_data(ZIO_COMPRESS_LZ4,
9902-
abd_buf->abd, tmpbuf, sizeof (*lb));
9904+
abd_buf->abd, tmpbuf, sizeof (*lb), dev->l2ad_spa->spa_max_ashift);
99039905

99049906
/* a log block is never entirely zero */
99059907
ASSERT(psize != 0);

module/zfs/zio.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Copyright (c) 2011, 2019 by Delphix. All rights reserved.
2424
* Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
2525
* Copyright (c) 2017, Intel Corporation.
26+
* Copyright (c) 2020 by George Melikov. All rights reserved.
2627
*/
2728

2829
#include <sys/sysmacros.h>
@@ -1676,7 +1677,8 @@ zio_write_compress(zio_t *zio)
16761677
if (compress != ZIO_COMPRESS_OFF &&
16771678
!(zio->io_flags & ZIO_FLAG_RAW_COMPRESS)) {
16781679
void *cbuf = zio_buf_alloc(lsize);
1679-
psize = zio_compress_data(compress, zio->io_abd, cbuf, lsize);
1680+
psize = zio_compress_data(compress, zio->io_abd, cbuf, lsize,
1681+
spa->spa_max_ashift);
16801682
if (psize == 0 || psize == lsize) {
16811683
compress = ZIO_COMPRESS_OFF;
16821684
zio_buf_free(cbuf, lsize);
@@ -1739,7 +1741,7 @@ zio_write_compress(zio_t *zio)
17391741
* to a hole.
17401742
*/
17411743
psize = zio_compress_data(ZIO_COMPRESS_EMPTY,
1742-
zio->io_abd, NULL, lsize);
1744+
zio->io_abd, NULL, lsize, 0);
17431745
if (psize == 0)
17441746
compress = ZIO_COMPRESS_OFF;
17451747
} else {

module/zfs/zio_compress.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222
/*
2323
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2424
* Use is subject to license terms.
25-
*/
26-
/*
2725
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
28-
*/
29-
30-
/*
3126
* Copyright (c) 2013, 2018 by Delphix. All rights reserved.
27+
* Copyright (c) 2020 by George Melikov. All rights reserved.
3228
*/
3329

3430
#include <sys/zfs_context.h>
@@ -102,7 +98,8 @@ zio_compress_zeroed_cb(void *data, size_t len, void *private)
10298
}
10399

104100
size_t
105-
zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
101+
zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len,
102+
int compress_threshold)
106103
{
107104
size_t c_len, d_len;
108105
zio_compress_info_t *ci = &zio_compress_table[c];
@@ -120,8 +117,24 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
120117
if (c == ZIO_COMPRESS_EMPTY)
121118
return (s_len);
122119

123-
/* Compress at least 12.5% */
124-
d_len = s_len - (s_len >> 3);
120+
/*
121+
* If data was compressed and passed ratio checks before -
122+
* we can skip these checks for reproducible results,
123+
* so set compress_threshold=0 for reproducibility of ARC checks.
124+
*/
125+
if (compress_threshold > 0) {
126+
/* Data is already less or equal to compress threshold */
127+
if (s_len <= compress_threshold)
128+
return (s_len);
129+
130+
/*
131+
* Write compressed only if there is at least
132+
* one sector compressed
133+
*/
134+
d_len = s_len - compress_threshold;
135+
} else {
136+
d_len = s_len;
137+
}
125138

126139
/* No compression algorithms can read from ABDs directly */
127140
void *tmp = abd_borrow_buf_copy(src, s_len);
@@ -131,7 +144,6 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
131144
if (c_len > d_len)
132145
return (s_len);
133146

134-
ASSERT3U(c_len, <=, d_len);
135147
return (c_len);
136148
}
137149

0 commit comments

Comments
 (0)