Skip to content

Commit c147e6d

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. Signed-off-by: George Melikov <[email protected]>
1 parent a7929f3 commit c147e6d

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.\" Copyright (c) 2013 by Turbo Fredriksson <[email protected]>. All rights reserved.
33
.\" Copyright (c) 2019 by Delphix. All rights reserved.
44
.\" Copyright (c) 2019 Datto Inc.
5+
.\" Copyright (c) 2019 by George Melikov <[email protected]>. All rights reserved.
56
.\" The contents of this file are subject to the terms of the Common Development
67
.\" and Distribution License (the "License"). You may not use this file except
78
.\" in compliance with the License. You can obtain a copy of the license at
@@ -408,7 +409,7 @@ Default value: \fB16,777,216\fR (16MB)
408409
.RS 12n
409410
If we are not searching forward (due to metaslab_df_max_search,
410411
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.
412+
what segment is used. If it is set, we will use the largest free segment.
412413
If it is not set, we will use a segment of exactly the requested size (or
413414
larger).
414415
.sp
@@ -3103,7 +3104,7 @@ Default value: \fB25\fR.
31033104
\fBzfs_sync_pass_dont_compress\fR (int)
31043105
.ad
31053106
.RS 12n
3106-
Starting in this sync pass, we disable compression (including of metadata).
3107+
Starting in this sync pass, we disable compression (including of metadata).
31073108
With the default setting, in practice, we don't have this many sync passes,
31083109
so this has no effect.
31093110
.sp

man/man8/zfsprops.8

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,11 @@ is selected, compression will explicitly check for blocks consisting of only
854854
zeroes (the NUL byte). When a zero-filled block is detected, it is stored as
855855
a hole and not compressed using the indicated compression algorithm.
856856
.Pp
857-
Any block being compressed must be no larger than 7/8 of its original size
858-
after compression, otherwise the compression will not be considered worthwhile
859-
and the block saved uncompressed. Note that when the logical block is less than
860-
8 times the disk sector size this effectively reduces the necessary compression
861-
ratio; for example 8k blocks on disks with 4k disk sectors must compress to 1/2
857+
Block must be compressed by at least max ashift of pool vdevs, otherwise
858+
the compression will not be considered worthwhile and the block saved
859+
uncompressed. Note that when the logical block is less than 2 times the disk
860+
sector size this effectively reduces the necessary compression ratio;
861+
for example 8k blocks on disks with 4k disk sectors must compress to 1/2
862862
or less of their original size.
863863
.It Xo
864864
.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+
PAGESIZE);
85358537
ASSERT3U(psize, <=, HDR_GET_PSIZE(hdr));
85368538
if (psize < asize)
85378539
bzero((char *)tmp + psize, asize - psize);
@@ -9901,7 +9903,7 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb)
99019903
/* try to compress the buffer */
99029904
list_insert_tail(&cb->l2wcb_abd_list, abd_buf);
99039905
psize = zio_compress_data(ZIO_COMPRESS_LZ4,
9904-
abd_buf->abd, tmpbuf, sizeof (*lb));
9906+
abd_buf->abd, tmpbuf, sizeof (*lb), dev->l2ad_spa->spa_max_ashift);
99059907

99069908
/* a log block is never entirely zero */
99079909
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)