Skip to content

Commit 9759c60

Browse files
edillmannbehlendorf
authored andcommitted
Illumos #3035 LZ4 compression support in ZFS and GRUB
3035 LZ4 compression support in ZFS and GRUB Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Christopher Siden <christopher.siden@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Approved by: Christopher Siden <csiden@delphix.com> References: illumos/illumos-gate@a6f561b https://www.illumos.org/issues/3035 http://wiki.illumos.org/display/illumos/LZ4+Compression+In+ZFS This patch has been slightly modified from the upstream Illumos version to be compatible with Linux. Due to the very limited stack space in the kernel a lz4 workspace kmem cache is used. Since we are using gcc we are also able to take advantage of the gcc optimized __builtin_ctz functions. Support for GRUB has been dropped from this patch. That code is available but those changes will need to made to the upstream GRUB package. Lastly, several hunks of dead code were dropped for clarity. They include the functions real_LZ4_uncompress(), LZ4_compressBound() and the Visual Studio specific hunks wrapped in _MSC_VER. Ported-by: Eric Dillmann <eric@jave.fr> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #1217
1 parent ff5b1c8 commit 9759c60

File tree

13 files changed

+1188
-2
lines changed

13 files changed

+1188
-2
lines changed

‎include/sys/zio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/*
2626
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
2727
* Copyright (c) 2012 by Delphix. All rights reserved.
28+
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
2829
*/
2930

3031
#ifndef _ZIO_H
@@ -108,6 +109,7 @@ enum zio_compress {
108109
ZIO_COMPRESS_GZIP_8,
109110
ZIO_COMPRESS_GZIP_9,
110111
ZIO_COMPRESS_ZLE,
112+
ZIO_COMPRESS_LZ4,
111113
ZIO_COMPRESS_FUNCTIONS
112114
};
113115

@@ -116,6 +118,7 @@ enum zio_compress {
116118

117119
#define BOOTFS_COMPRESS_VALID(compress) \
118120
((compress) == ZIO_COMPRESS_LZJB || \
121+
(compress) == ZIO_COMPRESS_LZ4 || \
119122
((compress) == ZIO_COMPRESS_ON && \
120123
ZIO_COMPRESS_ON_VALUE == ZIO_COMPRESS_LZJB) || \
121124
(compress) == ZIO_COMPRESS_OFF)

‎include/sys/zio_compress.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ typedef struct zio_compress_info {
5353

5454
extern zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS];
5555

56+
/*
57+
* lz4 compression init & free
58+
*/
59+
extern void lz4_init(void);
60+
extern void lz4_fini(void);
61+
5662
/*
5763
* Compression routines.
5864
*/
@@ -68,6 +74,10 @@ extern size_t zle_compress(void *src, void *dst, size_t s_len, size_t d_len,
6874
int level);
6975
extern int zle_decompress(void *src, void *dst, size_t s_len, size_t d_len,
7076
int level);
77+
extern size_t lz4_compress(void *src, void *dst, size_t s_len, size_t d_len,
78+
int level);
79+
extern int lz4_decompress(void *src, void *dst, size_t s_len, size_t d_len,
80+
int level);
7181

7282
/*
7383
* Compress and decompress data if necessary.

‎include/zfeature_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/*
2323
* Copyright (c) 2012 by Delphix. All rights reserved.
24+
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
2425
*/
2526

2627
#ifndef _ZFEATURE_COMMON_H
@@ -52,6 +53,7 @@ typedef int (zfeature_func_t)(zfeature_info_t *fi, void *arg);
5253
typedef enum spa_feature {
5354
SPA_FEATURE_ASYNC_DESTROY,
5455
SPA_FEATURE_EMPTY_BPOBJ,
56+
SPA_FEATURE_LZ4_COMPRESS,
5557
SPA_FEATURES
5658
} spa_feature_t;
5759

‎lib/libzpool/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ libzpool_la_SOURCES = \
4848
$(top_srcdir)/module/zfs/fm.c \
4949
$(top_srcdir)/module/zfs/gzip.c \
5050
$(top_srcdir)/module/zfs/lzjb.c \
51+
$(top_srcdir)/module/zfs/lz4.c \
5152
$(top_srcdir)/module/zfs/metaslab.c \
5253
$(top_srcdir)/module/zfs/refcount.c \
5354
$(top_srcdir)/module/zfs/rrwlock.c \

‎man/man5/zpool-features.5

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'\" te
22
.\" Copyright (c) 2012 by Delphix. All rights reserved.
3+
.\" Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
34
.\" The contents of this file are subject to the terms of the Common Development
45
.\" and Distribution License (the "License"). You may not use this file except
56
.\" in compliance with the License. You can obtain a copy of the license at
@@ -197,5 +198,38 @@ This feature is \fBactive\fR while there are any filesystems, volumes,
197198
or snapshots which were created after enabling this feature.
198199
.RE
199200

201+
.sp
202+
.ne 2
203+
.na
204+
\fB\fBlz4_compress\fR\fR
205+
.ad
206+
.RS 4n
207+
.TS
208+
l l .
209+
GUID org.illumos:lz4_compress
210+
READ\-ONLY COMPATIBLE no
211+
DEPENDENCIES none
212+
.TE
213+
214+
\fBlz4\fR is a high-performance real-time compression algorithm that
215+
features significantly faster compression and decompression as well as a
216+
higher compression ratio than the older \fBlzjb\fR compression.
217+
Typically, \fBlz4\fR compression is approximately 50% faster on
218+
compressible data and 200% faster on incompressible data than
219+
\fBlzjb\fR. It is also approximately 80% faster on decompression, while
220+
giving approximately 10% better compression ratio.
221+
222+
When the \fBlz4_compress\fR feature is set to \fBenabled\fR, the
223+
administrator can turn on \fBlz4\fR compression on any dataset on the
224+
pool using the \fBzfs\fR(1M) command. Please note that doing so will
225+
immediately activate the \fBlz4_compress\fR feature on the underlying
226+
pool (even before any data is written). Since this feature is not
227+
read-only compatible, this operation will render the pool unimportable
228+
on systems without support for the \fBlz4_compress\fR feature. At the
229+
moment, this operation cannot be reversed. Booting off of
230+
\fBlz4\fR-compressed root pools is supported.
231+
232+
.RE
233+
200234
.SH "SEE ALSO"
201235
\fBzpool\fR(1M)

‎man/man8/zfs.8

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
.\" Copyright (c) 2012 by Delphix. All rights reserved.
2626
.\" Copyright (c) 2012, Joyent, Inc. All rights reserved.
2727
.\" Copyright 2012 Nexenta Systems, Inc. All Rights Reserved.
28+
.\" Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
2829
.\"
2930
.TH zfs 8 "Jan 10, 2013" "ZFS pool 28, filesystem 5" "System Administration Commands"
3031
.SH NAME
@@ -731,7 +732,7 @@ Changing this property affects only newly-written data.
731732
.ne 2
732733
.mk
733734
.na
734-
\fBcompression\fR=\fBon\fR | \fBoff\fR | \fBlzjb\fR | \fBgzip\fR | \fBgzip-\fR\fIN\fR | \fBzle\fR
735+
\fBcompression\fR=\fBon\fR | \fBoff\fR | \fBlzjb\fR | \fBgzip\fR | \fBgzip-\fR\fIN\fR | \fBzle\fR | \fBlz4\fR
735736
.ad
736737
.sp .6
737738
.RS 4n
@@ -741,6 +742,14 @@ The \fBgzip\fR compression algorithm uses the same compression as the \fBgzip\fR
741742
.sp
742743
The \fBzle\fR (zero-length encoding) compression algorithm is a fast and simple algorithm to eliminate runs of zeroes.
743744
.sp
745+
The \fBlz4\fR compression algorithm is a high-performance replacement
746+
for the \fBlzjb\fR algorithm. It features significantly faster
747+
compression and decompression, as well as a moderately higher
748+
compression ratio than \fBlzjb\fR, but can only be used on pools with
749+
the \fBlz4_compress\fR feature set to \fIenabled\fR. See
750+
\fBzpool-features\fR(5) for details on ZFS feature flags and the
751+
\fBlz4_compress\fR feature.
752+
.sp
744753
This property can also be referred to by its shortened column name \fBcompress\fR. Changing this property affects only newly-written data.
745754
.RE
746755

���module/zcommon/zfs_prop.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ zfs_prop_init(void)
9696
{ "gzip-8", ZIO_COMPRESS_GZIP_8 },
9797
{ "gzip-9", ZIO_COMPRESS_GZIP_9 },
9898
{ "zle", ZIO_COMPRESS_ZLE },
99+
{ "lz4", ZIO_COMPRESS_LZ4 },
99100
{ NULL }
100101
};
101102

@@ -211,7 +212,7 @@ zfs_prop_init(void)
211212
zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
212213
ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
213214
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
214-
"on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS",
215+
"on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", "COMPRESS",
215216
compress_table);
216217
zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
217218
PROP_INHERIT, ZFS_TYPE_FILESYSTEM,

‎module/zfs/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ $(MODULE)-objs += @top_srcdir@/module/zfs/dsl_synctask.o
3232
$(MODULE)-objs += @top_srcdir@/module/zfs/fm.o
3333
$(MODULE)-objs += @top_srcdir@/module/zfs/gzip.o
3434
$(MODULE)-objs += @top_srcdir@/module/zfs/lzjb.o
35+
$(MODULE)-objs += @top_srcdir@/module/zfs/lz4.o
3536
$(MODULE)-objs += @top_srcdir@/module/zfs/metaslab.o
3637
$(MODULE)-objs += @top_srcdir@/module/zfs/refcount.o
3738
$(MODULE)-objs += @top_srcdir@/module/zfs/rrwlock.o

0 commit comments

Comments
 (0)