Skip to content

Commit

Permalink
Add lz4hc compression type
Browse files Browse the repository at this point in the history
Issue #1900
  • Loading branch information
vozhyk- committed Oct 10, 2015
1 parent 8f90f73 commit ab19f09
Show file tree
Hide file tree
Showing 13 changed files with 1,164 additions and 168 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ to the project and deserve to be acknowledged.
Suman Chakravartula <suman@gogrid.com>
Tim Haley <Tim.Haley@Sun.COM>
Turbo Fredriksson <turbo@bayour.com>
Witaut Bajaryn <vitaut.bayaryn@gmail.com>
Xin Li <delphij@FreeBSD.org>
Yuxuan Shui <yshuiv7@gmail.com>
Zachary Bedell <zac@thebedells.org>
Expand Down
24 changes: 16 additions & 8 deletions cmd/dbufstat/dbufstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,22 @@ def get_typestring(t):


def get_compstring(c):
comp_strings = ["ZIO_COMPRESS_INHERIT", "ZIO_COMPRESS_ON",
"ZIO_COMPRESS_OFF", "ZIO_COMPRESS_LZJB",
"ZIO_COMPRESS_EMPTY", "ZIO_COMPRESS_GZIP_1",
"ZIO_COMPRESS_GZIP_2", "ZIO_COMPRESS_GZIP_3",
"ZIO_COMPRESS_GZIP_4", "ZIO_COMPRESS_GZIP_5",
"ZIO_COMPRESS_GZIP_6", "ZIO_COMPRESS_GZIP_7",
"ZIO_COMPRESS_GZIP_8", "ZIO_COMPRESS_GZIP_9",
"ZIO_COMPRESS_ZLE", "ZIO_COMPRESS_LZ4",
comp_strings = ["ZIO_COMPRESS_INHERIT", "ZIO_COMPRESS_ON",
"ZIO_COMPRESS_OFF", "ZIO_COMPRESS_LZJB",
"ZIO_COMPRESS_EMPTY", "ZIO_COMPRESS_GZIP_1",
"ZIO_COMPRESS_GZIP_2", "ZIO_COMPRESS_GZIP_3",
"ZIO_COMPRESS_GZIP_4", "ZIO_COMPRESS_GZIP_5",
"ZIO_COMPRESS_GZIP_6", "ZIO_COMPRESS_GZIP_7",
"ZIO_COMPRESS_GZIP_8", "ZIO_COMPRESS_GZIP_9",
"ZIO_COMPRESS_ZLE", "ZIO_COMPRESS_LZ4",
"ZIO_COMPRESS_LZ4HC_1", "ZIO_COMPRESS_LZ4HC_2",
"ZIO_COMPRESS_LZ4HC_3", "ZIO_COMPRESS_LZ4HC_4",
"ZIO_COMPRESS_LZ4HC_5", "ZIO_COMPRESS_LZ4HC_6",
"ZIO_COMPRESS_LZ4HC_7", "ZIO_COMPRESS_LZ4HC_8",
"ZIO_COMPRESS_LZ4HC_9", "ZIO_COMPRESS_LZ4HC_10",
"ZIO_COMPRESS_LZ4HC_11", "ZIO_COMPRESS_LZ4HC_12",
"ZIO_COMPRESS_LZ4HC_13", "ZIO_COMPRESS_LZ4HC_14",
"ZIO_COMPRESS_LZ4HC_15", "ZIO_COMPRESS_LZ4HC_16",
"ZIO_COMPRESS_FUNCTION"]

# If "-rr" option is used, don't convert to string representation
Expand Down
200 changes: 200 additions & 0 deletions include/sys/lz4_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
* LZ4 - Fast LZ compression algorithm
* Header File
* Copyright (C) 2011-2015, Yann Collet.
* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* You can contact the author at :
* - LZ4 source repository : https://github.com/Cyan4973/lz4
* - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
*/

#ifndef _SYS_LZ4_IMPL_H
#define _SYS_LZ4_IMPL_H

#include <sys/zfs_context.h>

#ifdef __cplusplus
extern "C" {
#endif

/* CPU Feature Detection */
/*
* LZ4_FORCE_SW_BITCOUNT
* Define this parameter if your target system or compiler does not support
* hardware bit count
*
* Illumos : we can't use GCC's __builtin_ctz family of builtins in the
* kernel
* Linux : we can use GCC's __builtin_ctz family of builtins in the
* kernel
*/
#undef LZ4_FORCE_SW_BITCOUNT
#if defined(__sparc)
#define LZ4_FORCE_SW_BITCOUNT
#endif

/* Compiler Options */
#define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)

#if (LZ4_GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)
#define expect(expr, value) (__builtin_expect((expr), (value)))
#else
#define expect(expr, value) (expr)
#endif

#ifndef likely
#define likely(expr) expect((expr) != 0, 1)
#endif
#ifndef unlikely
#define unlikely(expr) expect((expr) != 0, 0)
#endif

/* Basic Types */
typedef uint8_t BYTE;
typedef uint16_t U16;
typedef uint32_t U32;
typedef int32_t S32;
typedef uint64_t U64;

/* Common Constants */
#define MINMATCH 4

#define COPYLENGTH 8
#define LASTLITERALS 5
#define MFLIMIT (COPYLENGTH+MINMATCH)

#define MAXD_LOG 16
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)

#define ML_BITS 4
#define ML_MASK ((1U<<ML_BITS)-1)
#define RUN_BITS (8-ML_BITS)
#define RUN_MASK ((1U<<RUN_BITS)-1)

/* Reading and writing into memory */
#define STEPSIZE sizeof (size_t)

static unsigned
LZ4_64bits(void)
{
return (sizeof (void *) == 8);
}

static unsigned
LZ4_isLittleEndian(void)
{
/* don't use static : performance detrimental */
const union {
U32 i;
BYTE c[4];
} one = { 1 };

return (one.c[0]);
}

/* Common functions */
static unsigned LZ4_NbCommonBytes(register size_t val)
{
if (LZ4_isLittleEndian()) {
if (LZ4_64bits()) {
#if (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && \
!defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_ctzll((U64)val) >> 3);
#else
static const int DeBruijnBytePos[64] =
{ 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7,
0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7,
7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6,
7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7
};
return (DeBruijnBytePos[
((U64)((val & -(long long)val) *
0x0218A392CDABBD3FULL)) >> 58]);
#endif
} else { /* 32 bits */

#if (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && \
!defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_ctz((U32)val) >> 3);
#else
static const int DeBruijnBytePos[32] =
{ 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1,
3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1
};
return (DeBruijnBytePos[((U32)((val & -(S32)val) *
0x077CB531U)) >> 27]);
#endif
}
} else { /* Big Endian CPU */

if (LZ4_64bits()) {
#if (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && \
!defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_clzll((U64)val) >> 3);
#else
unsigned r;
if (!(val >> 32)) {
r = 4;
} else {
r = 0;
val >>= 32;
}
if (!(val >> 16)) {
r += 2;
val >>= 8;
} else {
val >>= 24;
}
r += (!val);
return (r);
#endif
} else { /* 32 bits */

#if (defined(__clang__) || (LZ4_GCC_VERSION >= 304)) && \
!defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_clz((U32)val) >> 3);
#else
unsigned r;
if (!(val >> 16)) {
r = 2;
val >>= 8;
} else {
r = 0;
val >>= 24;
}
r += (!val);
return (r);
#endif
}
}
}

#ifdef __cplusplus
}
#endif

#endif /* _SYS_LZ4_IMPL_H */
17 changes: 17 additions & 0 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
* Copyright (c) 2015 by Witaut Bajaryn. All rights reserved.
*/

#ifndef _ZIO_H
Expand Down Expand Up @@ -114,6 +115,22 @@ enum zio_compress {
ZIO_COMPRESS_GZIP_9,
ZIO_COMPRESS_ZLE,
ZIO_COMPRESS_LZ4,
ZIO_COMPRESS_LZ4HC_1,
ZIO_COMPRESS_LZ4HC_2,
ZIO_COMPRESS_LZ4HC_3,
ZIO_COMPRESS_LZ4HC_4,
ZIO_COMPRESS_LZ4HC_5,
ZIO_COMPRESS_LZ4HC_6,
ZIO_COMPRESS_LZ4HC_7,
ZIO_COMPRESS_LZ4HC_8,
ZIO_COMPRESS_LZ4HC_9,
ZIO_COMPRESS_LZ4HC_10,
ZIO_COMPRESS_LZ4HC_11,
ZIO_COMPRESS_LZ4HC_12,
ZIO_COMPRESS_LZ4HC_13,
ZIO_COMPRESS_LZ4HC_14,
ZIO_COMPRESS_LZ4HC_15,
ZIO_COMPRESS_LZ4HC_16,
ZIO_COMPRESS_FUNCTIONS
};

Expand Down
6 changes: 5 additions & 1 deletion include/sys/zio_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ typedef const struct zio_compress_info {
extern zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS];

/*
* lz4 compression init & free
* lz4 and lz4hc compression init & free
*/
extern void lz4_init(void);
extern void lz4_fini(void);
extern void lz4hc_init(void);
extern void lz4hc_fini(void);

/*
* Compression routines.
Expand All @@ -77,6 +79,8 @@ extern size_t lz4_compress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern int lz4_decompress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
int level);
extern size_t lz4hc_compress_zfs(void *src, void *dst, size_t s_len,
size_t d_len, int level);

/*
* Compress and decompress data if necessary.
Expand Down
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ KERNEL_C = \
gzip.c \
lzjb.c \
lz4.c \
lz4hc.c \
metaslab.c \
multilist.c \
range_tree.c \
Expand Down
24 changes: 22 additions & 2 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
* Copyright (c) 2015 by Witaut Bajaryn. All rights reserved.
*/

/* Portions Copyright 2010 Robert Milkowski */
Expand Down Expand Up @@ -98,6 +99,24 @@ zfs_prop_init(void)
{ "gzip-9", ZIO_COMPRESS_GZIP_9 },
{ "zle", ZIO_COMPRESS_ZLE },
{ "lz4", ZIO_COMPRESS_LZ4 },
{ "lz4hc", ZIO_COMPRESS_LZ4HC_9 }, /* lz4hc default */
{ "lz4hc-1", ZIO_COMPRESS_LZ4HC_1 },
{ "lz4hc-1", ZIO_COMPRESS_LZ4HC_1 },
{ "lz4hc-2", ZIO_COMPRESS_LZ4HC_2 },
{ "lz4hc-3", ZIO_COMPRESS_LZ4HC_3 },
{ "lz4hc-4", ZIO_COMPRESS_LZ4HC_4 },
{ "lz4hc-5", ZIO_COMPRESS_LZ4HC_5 },
{ "lz4hc-6", ZIO_COMPRESS_LZ4HC_6 },
{ "lz4hc-7", ZIO_COMPRESS_LZ4HC_7 },
{ "lz4hc-8", ZIO_COMPRESS_LZ4HC_8 },
{ "lz4hc-9", ZIO_COMPRESS_LZ4HC_9 },
{ "lz4hc-10", ZIO_COMPRESS_LZ4HC_10 },
{ "lz4hc-11", ZIO_COMPRESS_LZ4HC_11 },
{ "lz4hc-12", ZIO_COMPRESS_LZ4HC_12 },
{ "lz4hc-13", ZIO_COMPRESS_LZ4HC_13 },
{ "lz4hc-14", ZIO_COMPRESS_LZ4HC_14 },
{ "lz4hc-15", ZIO_COMPRESS_LZ4HC_15 },
{ "lz4hc-16", ZIO_COMPRESS_LZ4HC_16 },
{ NULL }
};

Expand Down Expand Up @@ -238,8 +257,9 @@ zfs_prop_init(void)
zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
"on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", "COMPRESS",
compress_table);
"on | off | lzjb | gzip | gzip-[1-9] | zle | lz4 | "
"lz4hc | lz4hc-[1-16]",
"COMPRESS", compress_table);
zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
"hidden | visible", "SNAPDIR", snapdir_table);
Expand Down
1 change: 1 addition & 0 deletions module/zfs/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $(MODULE)-objs += fm.o
$(MODULE)-objs += gzip.o
$(MODULE)-objs += lzjb.o
$(MODULE)-objs += lz4.o
$(MODULE)-objs += lz4hc.o
$(MODULE)-objs += metaslab.o
$(MODULE)-objs += multilist.o
$(MODULE)-objs += range_tree.o
Expand Down
Loading

0 comments on commit ab19f09

Please sign in to comment.