Skip to content

Commit 99197f0

Browse files
Justin T. Gibbsbehlendorf
authored andcommitted
Illumos 5661 - ZFS: "compression = on" should use lz4 if feature is enabled
5661 ZFS: "compression = on" should use lz4 if feature is enabled Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Reviewed by: Xin LI <delphij@freebsd.org> Approved by: Robert Mustacchi <rm@joyent.com> References: illumos/illumos-gate@db1741f https://www.illumos.org/issues/5661 Ported-by: kernelOfTruth kerneloftruth@gmail.com Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #3571
1 parent 15cfbb3 commit 99197f0

File tree

5 files changed

+61
-31
lines changed

5 files changed

+61
-31
lines changed

include/sys/zio.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,19 @@ enum zio_compress {
123123
*/
124124
#define ZIO_COMPRESS_LEGACY_FUNCTIONS ZIO_COMPRESS_LZ4
125125

126-
#define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB
127-
#define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF
126+
/*
127+
* The meaning of "compress = on" selected by the compression features enabled
128+
* on a given pool.
129+
*/
130+
#define ZIO_COMPRESS_LEGACY_ON_VALUE ZIO_COMPRESS_LZJB
131+
#define ZIO_COMPRESS_LZ4_ON_VALUE ZIO_COMPRESS_LZ4
132+
133+
#define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF
128134

129135
#define BOOTFS_COMPRESS_VALID(compress) \
130136
((compress) == ZIO_COMPRESS_LZJB || \
131137
(compress) == ZIO_COMPRESS_LZ4 || \
132-
((compress) == ZIO_COMPRESS_ON && \
133-
ZIO_COMPRESS_ON_VALUE == ZIO_COMPRESS_LZJB) || \
138+
(compress) == ZIO_COMPRESS_ON || \
134139
(compress) == ZIO_COMPRESS_OFF)
135140

136141
/*
@@ -543,8 +548,8 @@ extern enum zio_checksum zio_checksum_select(enum zio_checksum child,
543548
enum zio_checksum parent);
544549
extern enum zio_checksum zio_checksum_dedup_select(spa_t *spa,
545550
enum zio_checksum child, enum zio_checksum parent);
546-
extern enum zio_compress zio_compress_select(enum zio_compress child,
547-
enum zio_compress parent);
551+
extern enum zio_compress zio_compress_select(spa_t *spa,
552+
enum zio_compress child, enum zio_compress parent);
548553

549554
extern void zio_suspend(spa_t *spa, zio_t *zio);
550555
extern int zio_resume(spa_t *spa);

man/man8/zfs.8

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,15 +840,25 @@ Changing this property affects only newly-written data.
840840
.ne 2
841841
.mk
842842
.na
843-
\fBcompression\fR=\fBon\fR | \fBoff\fR | \fBlzjb\fR | \fBgzip\fR | \fBgzip-\fR\fIN\fR | \fBzle\fR | \fBlz4\fR
843+
\fB\fBcompression\fR=\fBon\fR | \fBoff\fR | \fBlzjb\fR | \fBlz4\fR |
844+
\fBgzip\fR | \fBgzip-\fR\fIN\fR | \fBzle\fR\fR
844845
.ad
845846
.sp .6
846847
.RS 4n
847-
Controls the compression algorithm used for this dataset. The \fBlzjb\fR compression algorithm is optimized for performance while providing decent data compression. Setting compression to \fBon\fR uses the \fBlzjb\fR compression algorithm.
848+
Controls the compression algorithm used for this dataset.
848849
.sp
849-
The \fBgzip\fR compression algorithm uses the same compression as the \fBgzip\fR(1) command. You can specify the \fBgzip\fR level by using the value \fBgzip-\fR\fIN\fR where \fIN\fR is an integer from 1 (fastest) to 9 (best compression ratio). Currently, \fBgzip\fR is equivalent to \fBgzip-6\fR (which is also the default for \fBgzip\fR(1)).
850+
Setting compression to \fBon\fR indicates that the current default
851+
compression algorithm should be used. The default balances compression
852+
and decompression speed, with compression ratio and is expected to
853+
work well on a wide variety of workloads. Unlike all other settings for
854+
this property, \fBon\fR does not select a fixed compression type. As
855+
new compression algorithms are added to ZFS and enabled on a pool, the
856+
default compression algorithm may change. The current default compression
857+
algorthm is either \fBlzjb\fR or, if the \fBlz4_compress\fR feature is
858+
enabled, \fBlz4\fR.
850859
.sp
851-
The \fBzle\fR (zero-length encoding) compression algorithm is a fast and simple algorithm to eliminate runs of zeroes.
860+
The \fBlzjb\fR compression algorithm is optimized for performance while
861+
providing decent data compression.
852862
.sp
853863
The \fBlz4\fR compression algorithm is a high-performance replacement
854864
for the \fBlzjb\fR algorithm. It features significantly faster
@@ -858,7 +868,15 @@ the \fBlz4_compress\fR feature set to \fIenabled\fR. See
858868
\fBzpool-features\fR(5) for details on ZFS feature flags and the
859869
\fBlz4_compress\fR feature.
860870
.sp
861-
This property can also be referred to by its shortened column name \fBcompress\fR. Changing this property affects only newly-written data.
871+
The \fBgzip\fR compression algorithm uses the same compression as
872+
the \fBgzip\fR(1) command. You can specify the \fBgzip\fR level by using the
873+
value \fBgzip-\fR\fIN\fR where \fIN\fR is an integer from 1 (fastest) to 9
874+
(best compression ratio). Currently, \fBgzip\fR is equivalent to \fBgzip-6\fR
875+
(which is also the default for \fBgzip\fR(1)). The \fBzle\fR compression
876+
algorithm compresses runs of zeros.
877+
.sp
878+
This property can also be referred to by its shortened column name
879+
\fBcompress\fR. Changing this property affects only newly-written data.
862880
.RE
863881

864882
.sp

module/zfs/dmu.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,19 +1864,15 @@ dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp)
18641864
* 3. all other level 0 blocks
18651865
*/
18661866
if (ismd) {
1867-
/*
1868-
* XXX -- we should design a compression algorithm
1869-
* that specializes in arrays of bps.
1870-
*/
1871-
boolean_t lz4_ac = spa_feature_is_active(os->os_spa,
1872-
SPA_FEATURE_LZ4_COMPRESS);
1873-
18741867
if (zfs_mdcomp_disable) {
18751868
compress = ZIO_COMPRESS_EMPTY;
1876-
} else if (lz4_ac) {
1877-
compress = ZIO_COMPRESS_LZ4;
18781869
} else {
1879-
compress = ZIO_COMPRESS_LZJB;
1870+
/*
1871+
* XXX -- we should design a compression algorithm
1872+
* that specializes in arrays of bps.
1873+
*/
1874+
compress = zio_compress_select(os->os_spa,
1875+
ZIO_COMPRESS_ON, ZIO_COMPRESS_ON);
18801876
}
18811877

18821878
/*
@@ -1909,7 +1905,8 @@ dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp)
19091905
compress = ZIO_COMPRESS_OFF;
19101906
checksum = ZIO_CHECKSUM_OFF;
19111907
} else {
1912-
compress = zio_compress_select(dn->dn_compress, compress);
1908+
compress = zio_compress_select(os->os_spa, dn->dn_compress,
1909+
compress);
19131910

19141911
checksum = (dedup_checksum == ZIO_CHECKSUM_OFF) ?
19151912
zio_checksum_select(dn->dn_checksum, checksum) :

module/zfs/dmu_objset.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ compression_changed_cb(void *arg, uint64_t newval)
163163
*/
164164
ASSERT(newval != ZIO_COMPRESS_INHERIT);
165165

166-
os->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE);
166+
os->os_compress = zio_compress_select(os->os_spa, newval,
167+
ZIO_COMPRESS_ON);
167168
}
168169

169170
static void
@@ -420,7 +421,7 @@ dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
420421
} else {
421422
/* It's the meta-objset. */
422423
os->os_checksum = ZIO_CHECKSUM_FLETCHER_4;
423-
os->os_compress = ZIO_COMPRESS_LZJB;
424+
os->os_compress = ZIO_COMPRESS_ON;
424425
os->os_copies = spa_max_replication(spa);
425426
os->os_dedup_checksum = ZIO_CHECKSUM_OFF;
426427
os->os_dedup_verify = B_FALSE;

module/zfs/zio_compress.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <sys/zfs_context.h>
3535
#include <sys/compress.h>
3636
#include <sys/spa.h>
37+
#include <sys/zfeature.h>
3738
#include <sys/zio.h>
3839
#include <sys/zio_compress.h>
3940

@@ -61,19 +62,27 @@ zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS] = {
6162
};
6263

6364
enum zio_compress
64-
zio_compress_select(enum zio_compress child, enum zio_compress parent)
65+
zio_compress_select(spa_t *spa, enum zio_compress child,
66+
enum zio_compress parent)
6567
{
68+
enum zio_compress result;
69+
6670
ASSERT(child < ZIO_COMPRESS_FUNCTIONS);
6771
ASSERT(parent < ZIO_COMPRESS_FUNCTIONS);
68-
ASSERT(parent != ZIO_COMPRESS_INHERIT && parent != ZIO_COMPRESS_ON);
72+
ASSERT(parent != ZIO_COMPRESS_INHERIT);
6973

70-
if (child == ZIO_COMPRESS_INHERIT)
71-
return (parent);
74+
result = child;
75+
if (result == ZIO_COMPRESS_INHERIT)
76+
result = parent;
7277

73-
if (child == ZIO_COMPRESS_ON)
74-
return (ZIO_COMPRESS_ON_VALUE);
78+
if (result == ZIO_COMPRESS_ON) {
79+
if (spa_feature_is_active(spa, SPA_FEATURE_LZ4_COMPRESS))
80+
result = ZIO_COMPRESS_LZ4_ON_VALUE;
81+
else
82+
result = ZIO_COMPRESS_LEGACY_ON_VALUE;
83+
}
7584

76-
return (child);
85+
return (result);
7786
}
7887

7988
size_t

0 commit comments

Comments
 (0)