Skip to contentSkip to conversation

Updated btrfs/crypto snappy interface ready for merging

PATCH In review Andi Kleen 12 participants 25 messages Jan 13, 2012 – Oct 9, 2012

Subsystems (3)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

This version has:

- Ported to latest tree
- Extensive testing and benchmarking (in its 3.0 based incarnation)
- A few cleanups
- Adds a minor performance improvement

Should be ready for pulling into the btrfs tree now. The crypto parts have been acked by Herbert.

The following changes since commit 2485a4b610171f4e1c4ab0d053569747795c1bbe:

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input (2012-01-12 12:40:41 -0800)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc snappy

Andi Kleen (3):
Add the snappy-c compressor to lib v2
BTRFS: Add snappy support v2
Add snappy interface to crypto API

 crypto/Kconfig         |    9 +
 crypto/Makefile        |    1 +
 crypto/snappy.c        |   99 ++++
 fs/btrfs/Kconfig       |    1 +
 fs/btrfs/Makefile      |    2 +-
 fs/btrfs/compression.c |    1 +
 fs/btrfs/compression.h |    1 +
 fs/btrfs/ctree.h       |    9 +-
 fs/btrfs/disk-io.c     |    2 +
 fs/btrfs/ioctl.c       |    4 +
 fs/btrfs/snappy.c      |  432 ++++++++++++++++
 fs/btrfs/super.c       |    9 +-
 include/linux/snappy.h |   26 +
 lib/Kconfig            |    6 +
 lib/Makefile           |    4 +
 lib/snappy.c           | 1300 ++++++++++++++++++++++++++++++++++++++++++++++++
 16 files changed, 1901 insertions(+), 5 deletions(-)
 create mode 100644 crypto/snappy.c
 create mode 100644 fs/btrfs/snappy.c
 create mode 100644 include/linux/snappy.h
 create mode 100644 lib/snappy.c

-Andi

author
#1 lore raw

PATCH 1/3 Add the snappy-c compressor to lib v2

From: Andi Kleen <[email protected]>

This is a C port of the google snappy compressor. It has roughly comparable compression to LZO, but is significantly faster on many file types. For example it beats all other compressors on already compressed data.

I ported the original C++ code over to C and did some changes to make it better fit into the kernel. It preallocates the worst case memory consumption now. While the code being larger than lzo it is still reasonable (about 5K on x86).

Decompression needs very little memory, Compression currently 192K on 64bit and 128K on 32bit. For comparison LZO compression needs 128K on 64bit and 64K on 32bit.

[This could be lowered significantly by not preallocating for most use cases, typically the footprint is much lower. The original C++ version only allocated most of this when (rarely) needed, but this is more problematic in the kernel]

There are some minor divergences from the Linux coding standards:
in particular I kept the C++/C99 style mixed statement/declarations. This was mainly to not diverge too much from the reference C++ source, so that improvements from there can be easily ported. There are some other left overs from the google style, but very little now.

Performance:

The compressor performs best on 64bit-LE systems, but is also quite good on 32bit. I haven't tested BE, but I don't expect that to add a lot of overhead.

Here is some performance data (32bit, Nehalem):
c/b = cycles/byte; lower numbers are better.

x86-64 executable: (compression minimally slower than qlz, but much better at decompression, lzo is left in the dust):

snappy: emacs-gtk: 11007968 b: ratio 0.38: comp 8.13 uncomp 2.65 c/b
lzo : emacs-gtk: 11007968 b: ratio 0.33: comp 12.74 uncomp 4.70 c/b
zlib1 : emacs-gtk: 11007968 b: ratio 0.27: comp 49.96 uncomp 13.14 c/b zlib3 : emacs-gtk: 11007968 b: ratio 0.26: comp 64.17 uncomp 12.33 c/b
lzf : emacs-gtk: 11007968 b: ratio 0.37: comp 9.85 uncomp 4.33 c/b
qlz : emacs-gtk: 11007968 b: ratio 0.34: comp 7.51 uncomp 6.28 c/b
fastlz: emacs-gtk: 11007968 b: ratio 0.37: comp 10.73 uncomp 4.97 c/b

Compressed data (beats everything else):

snappy: udev-151.tar.gz: 634842 b: ratio 1.00: comp 0.99 uncomp 0.33 c/b
lzo : udev-151.tar.gz: 634842 b: ratio 1.00: comp 41.44 uncomp 0.66 c/b
zlib1 : udev-151.tar.gz: 634842 b: ratio 1.00: comp 116.99 uncomp 3.94 c/b zlib3 : udev-151.tar.gz: 634842 b: ratio 1.00: comp 117.68 uncomp 3.94 c/b
lzf : udev-151.tar.gz: 634842 b: ratio 1.03: comp 16.32 uncomp 1.14 c/b
qlz : udev-151.tar.gz: 634842 b: ratio 1.00: comp 10.42 uncomp 0.42 c/b
fastlz: udev-151.tar.gz: 634842 b: ratio 1.03: comp 19.35 uncomp 2.07 c/b

Text file (compression somewhat slower than qlz, but decompression much better, lzo is much worse):

snappy: manual.txt: 445343 b: ratio 0.47: comp 12.01 uncomp 3.12 c/b
lzo : manual.txt: 445343 b: ratio 0.44: comp 16.32 uncomp 7.53 c/b
zlib1 : manual.txt: 445343 b: ratio 0.35: comp 56.37 uncomp 15.59 c/b zlib3 : manual.txt: 445343 b: ratio 0.31: comp 73.45 uncomp 13.99 c/b
lzf : manual.txt: 445343 b: ratio 0.46: comp 13.43 uncomp 5.47 c/b
qlz : manual.txt: 445343 b: ratio 0.44: comp 9.16 uncomp 8.19 c/b
fastlz: manual.txt: 445343 b: ratio 0.46: comp 14.22 uncomp 7.28 c/b

As you can see snappy is a good all-around compressor.

On 64bit the compression is even faster and beats everything else easily:

snappy: emacs-gtk: 11007968 b: ratio 0.38: comp 4.90 uncomp 2.65 c/b
lzo : emacs-gtk: 11007968 b: ratio 0.33: comp 11.24 uncomp 4.46 c/b
zlib1 : emacs-gtk: 11007968 b: ratio 0.27: comp 41.67 uncomp 11.13 c/b zlib3 : emacs-gtk: 11007968 b: ratio 0.26: comp 51.80 uncomp 10.54 c/b
lzf : emacs-gtk: 11007968 b: ratio 0.37: comp 8.79 uncomp 4.05 c/b
qlz : emacs-gtk: 11007968 b: ratio 0.34: comp 5.44 uncomp 5.46 c/b
fastlz: emacs-gtk: 11007968 b: ratio 0.37: comp 9.91 uncomp 4.77 c/b

On 64bit it's now nearly as fast as qlz on the text file too:

snappy: manual.txt: 445343 b: ratio 0.47: comp 7.79 uncomp 3.47 c/b
lzo : manual.txt: 445343 b: ratio 0.44: comp 15.46 uncomp 7.27 c/b
zlib1 : manual.txt: 445343 b: ratio 0.35: comp 45.79 uncomp 12.78 c/b zlib3 : manual.txt: 445343 b: ratio 0.31: comp 60.52 uncomp 11.72 c/b
lzf : manual.txt: 445343 b: ratio 0.46: comp 12.62 uncomp 5.30 c/b
qlz : manual.txt: 445343 b: ratio 0.44: comp 6.81 uncomp 7.65 c/b
fastlz: manual.txt: 445343 b: ratio 0.46: comp 13.75 uncomp 6.52 c/b

Overall it's a good alternative to lzo, with the only drawback being the somewhat higher memory use.

v2: Some minor performance improvements and cleanups. 32bit compression should be a few percent faster now.

---
 include/linux/snappy.h |   26 +
 lib/Kconfig            |    6 +
 lib/Makefile           |    4 +
 lib/snappy.c           | 1300 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1336 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/snappy.h
 create mode 100644 lib/snappy.c
include/linux/snappy.h new file +26 -0
new file mode 100644
index 0000000..4119803
@@ -0,0 +1,26 @@
+#ifndef _LINUX_SNAPPY_H
+#define _LINUX_SNAPPY_H 1
+
+#include <linux/types.h>
+
+/* Only needed for compression. This preallocates the worst case */
+struct snappy_env {
+	u16 *hash_table;
+	void *scratch;
+	void *scratch_output;
+};
+
+int snappy_init_env(struct snappy_env *env);
+void snappy_free_env(struct snappy_env *env);
+bool snappy_uncompress(const char *compressed, size_t n, char *uncompressed);
+int snappy_compress(struct snappy_env *env,
+		    const char *input,
+		    size_t input_length,
+		    char *compressed,
+		    size_t *compressed_length);
+bool snappy_uncompressed_length(const char *buf, size_t len, size_t *result);
+size_t snappy_max_compressed_length(size_t source_len);
+
+
+
+#endif
lib/Kconfig +6 -0
index 201e1b3..719e4f2 100644
@@ -310,4 +310,10 @@ config DIGSIG
 	  Digital signature verification. Currently only RSA is supported.
 	  Implementation is done using GnuPG MPI library
 
+config SNAPPY
+       tristate "Snappy compressor"
+       help
+          Add the snappy compressor. This is a reasonable compressor that
+	  compresses and decompresses extremly fast.
+
 endmenu
lib/Makefile +4 -0
index dace162..2f5f86a 100644
@@ -121,6 +121,10 @@ obj-$(CONFIG_DQL) += dynamic_queue_limits.o
 obj-$(CONFIG_MPILIB) += mpi/
 obj-$(CONFIG_DIGSIG) += digsig.o
 
+CFLAGS_snappy.o += $(call cc-disable-warning, declaration-after-statement) \
+		   -DNDEBUG=1
+obj-$(CONFIG_SNAPPY) += snappy.o
+
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
 
lib/snappy.c new file +1300 -0

1,300 lines not on this page · raw message

Signature · 1 line
1.7.7.4
#2 lore raw

Re: [PATCH 1/3] Add the snappy-c compressor to lib v2

On Thu, Jan 12, 2012 at 6:28 PM, Andi Kleen <[email protected]> wrote= :

Quoted 4 lines

From: Andi Kleen <[email protected]>

This is a C port of the google snappy compressor. It has roughly comparable compression to LZO, but is significantly faster on many fi=

le

Quoted 30 lines

types. For example it beats all other compressors on already compressed data.

I ported the original C++ code over to C and did some changes to make it better fit into the kernel. It preallocates the worst case memory consumption now. While the code being larger than lzo it is still reasonable (about 5K on x86).

Decompression needs very little memory, Compression currently 192K on 64bit and 128K on 32bit. For comparison LZO compression needs 128K on 64bit and 64K on 32bit.

[This could be lowered significantly by not preallocating for most use cases, typically the footprint is much lower. The original C++ version only allocated most of this when (rarely) needed, but this is more problematic in the kernel]

There are some minor divergences from the Linux coding standards:
in particular I kept the C++/C99 style mixed statement/declarations. This was mainly to not diverge too much from the reference C++ source, so that improvements from there can be easily ported. There are some other left overs from the google style, but very little now.

Performance:

The compressor performs best on 64bit-LE systems, but is also quite good on 32bit. I haven't tested BE, but I don't expect that to add a lot of overhead.

Quoted 8 lines

Here is some performance data (32bit, Nehalem):
c/b =3D cycles/byte; lower numbers are better.

x86-64 executable: (compression minimally slower than qlz, but much better at decompression, lzo is left in the dust):

snappy: emacs-gtk: 11007968 b: ratio 0.38: comp 8.13 uncomp 2.65 c/b lzo =A0 : emacs-gtk: 11007968 b: ratio 0.33: comp 12.74 uncomp 4.70 c=

/b

Quoted 1 line

zlib1 : emacs-gtk: 11007968 b: ratio 0.27: comp 49.96 uncomp 13.14 c/=

b

Quoted 1 line

zlib3 : emacs-gtk: 11007968 b: ratio 0.26: comp 64.17 uncomp 12.33 c/=

b

Quoted 1 line

lzf =A0 : emacs-gtk: 11007968 b: ratio 0.37: comp 9.85 uncomp 4.33 c/=

b

Quoted 1 line

qlz =A0 : emacs-gtk: 11007968 b: ratio 0.34: comp 7.51 uncomp 6.28 c/=

b

Quoted 5 lines

fastlz: emacs-gtk: 11007968 b: ratio 0.37: comp 10.73 uncomp 4.97 c/b

Compressed data (beats everything else):

snappy: udev-151.tar.gz: 634842 b: ratio 1.00: comp 0.99 uncomp 0.33 =

c/b

Quoted 1 line

lzo =A0 : udev-151.tar.gz: 634842 b: ratio 1.00: comp 41.44 uncomp 0.=

66 c/b

Quoted 1 line

zlib1 : udev-151.tar.gz: 634842 b: ratio 1.00: comp 116.99 uncomp 3.9=

4 c/b

Quoted 1 line

zlib3 : udev-151.tar.gz: 634842 b: ratio 1.00: comp 117.68 uncomp 3.9=

4 c/b

Quoted 1 line

lzf =A0 : udev-151.tar.gz: 634842 b: ratio 1.03: comp 16.32 uncomp 1.=

14 c/b

Quoted 1 line

qlz =A0 : udev-151.tar.gz: 634842 b: ratio 1.00: comp 10.42 uncomp 0.=

42 c/b

Quoted 1 line

fastlz: udev-151.tar.gz: 634842 b: ratio 1.03: comp 19.35 uncomp 2.07=

c/b

Quoted 6 lines

Text file (compression somewhat slower than qlz, but decompression much better, lzo is much worse):

snappy: manual.txt: 445343 b: ratio 0.47: comp 12.01 uncomp 3.12 c/b lzo =A0 : manual.txt: 445343 b: ratio 0.44: comp 16.32 uncomp 7.53 c/=

b

Quoted 3 lines

zlib1 : manual.txt: 445343 b: ratio 0.35: comp 56.37 uncomp 15.59 c/b zlib3 : manual.txt: 445343 b: ratio 0.31: comp 73.45 uncomp 13.99 c/b lzf =A0 : manual.txt: 445343 b: ratio 0.46: comp 13.43 uncomp 5.47 c/=

b

Quoted 6 lines

qlz =A0 : manual.txt: 445343 b: ratio 0.44: comp 9.16 uncomp 8.19 c/b
fastlz: manual.txt: 445343 b: ratio 0.46: comp 14.22 uncomp 7.28 c/b

As you can see snappy is a good all-around compressor.

On 64bit the compression is even faster and beats everything else eas=

ily:

Quoted 3 lines

snappy: emacs-gtk: 11007968 b: ratio 0.38: comp 4.90 uncomp 2.65 c/b lzo =A0 : emacs-gtk: 11007968 b: ratio 0.33: comp 11.24 uncomp 4.46 c=

/b

Quoted 1 line

zlib1 : emacs-gtk: 11007968 b: ratio 0.27: comp 41.67 uncomp 11.13 c/=

b

Quoted 1 line

zlib3 : emacs-gtk: 11007968 b: ratio 0.26: comp 51.80 uncomp 10.54 c/=

b

Quoted 1 line

lzf =A0 : emacs-gtk: 11007968 b: ratio 0.37: comp 8.79 uncomp 4.05 c/=

b

Quoted 1 line

qlz =A0 : emacs-gtk: 11007968 b: ratio 0.34: comp 5.44 uncomp 5.46 c/=

b

Quoted 6 lines

fastlz: emacs-gtk: 11007968 b: ratio 0.37: comp 9.91 uncomp 4.77 c/b

On 64bit it's now nearly as fast as qlz on the text file too:

snappy: manual.txt: 445343 b: ratio 0.47: comp 7.79 uncomp 3.47 c/b lzo =A0 : manual.txt: 445343 b: ratio 0.44: comp 15.46 uncomp 7.27 c/=

b

Quoted 3 lines

zlib1 : manual.txt: 445343 b: ratio 0.35: comp 45.79 uncomp 12.78 c/b zlib3 : manual.txt: 445343 b: ratio 0.31: comp 60.52 uncomp 11.72 c/b lzf =A0 : manual.txt: 445343 b: ratio 0.46: comp 12.62 uncomp 5.30 c/=

b

Quoted 6 lines

qlz =A0 : manual.txt: 445343 b: ratio 0.44: comp 6.81 uncomp 7.65 c/b
fastlz: manual.txt: 445343 b: ratio 0.46: comp 13.75 uncomp 6.52 c/b

Overall it's a good alternative to lzo, with the only drawback being the somewhat higher memory use.

Quoted 8 lines

v2: Some minor performance improvements and cleanups. 32bit compression should be a few percent faster now.

---
=A0include/linux/snappy.h | =A0 26 +
=A0lib/Kconfig =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A06 + =A0lib/Makefile =A0 =A0 =A0 =A0 =A0 | =A0 =A04 + =A0lib/snappy.c =A0 =A0 =A0 =A0 =A0 | 1300 ++++++++++++++++++++++++++=

++++++++++++++++++++++

Quoted 15 lines

=A04 files changed, 1336 insertions(+), 0 deletions(-) =A0create mode 100644 include/linux/snappy.h =A0create mode 100644 lib/snappy.c

include/linux/snappy.h new file +5 -0
new file mode 100644
index 0000000..4119803
@@ -0,0 +1,26 @@
+#ifndef _LINUX_SNAPPY_H
+#define _LINUX_SNAPPY_H 1
+
+#include <linux/types.h>
+

include/linux/snappy.h line 15

Quoted 10 lines
include/linux/snappy.h new file +10 -0
+/* Only needed for compression. This preallocates the worst case */
+struct snappy_env {
+ =A0 =A0 =A0 u16 *hash_table;
+ =A0 =A0 =A0 void *scratch;
+ =A0 =A0 =A0 void *scratch_output;
+};
+
+int snappy_init_env(struct snappy_env *env);
+void snappy_free_env(struct snappy_env *env);
+bool snappy_uncompress(const char *compressed, size_t n, char *uncom=

pressed);

include/linux/snappy.h line 21

Quoted 6 lines
include/linux/snappy.h new file +6 -0
+int snappy_compress(struct snappy_env *env,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *input,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t input_length,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *compressed,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t *compressed_length);
+bool snappy_uncompressed_length(const char *buf, size_t len, size_t =

*result);

Quoted 11 lines
include/linux/snappy.h new file +5 -0
+size_t snappy_max_compressed_length(size_t source_len);
+
+
+
+#endif
lib/Kconfig +0 -0
index 201e1b3..719e4f2 100644
@@ -310,4 +310,10 @@ config DIGSIG

=A0 =A0 =A0 =A0 =A0Digital signature verification. Currently only RSA=

is supported.

Quoted 6 lines

=A0 =A0 =A0 =A0 =A0Implementation is done using GnuPG MPI library

+config SNAPPY
+ =A0 =A0 =A0 tristate "Snappy compressor"
+ =A0 =A0 =A0 help
+ =A0 =A0 =A0 =A0 =A0Add the snappy compressor. This is a reasonable =

compressor that

Quoted 11 lines

+ =A0 =A0 =A0 =A0 compresses and decompresses extremly fast. +
=A0endmenu

lib/Makefile +0 -0
index dace162..2f5f86a 100644
@@ -121,6 +121,10 @@ obj-$(CONFIG_DQL) +=3D dynamic_queue_limits.o

=A0obj-$(CONFIG_MPILIB) +=3D mpi/
=A0obj-$(CONFIG_DIGSIG) +=3D digsig.o

Quoted 1 line

+CFLAGS_snappy.o +=3D $(call cc-disable-warning, declaration-after-st=

atement) \

Quoted 12 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-DNDEBUG=3D1

lib/Makefile +2 -0
+obj-$(CONFIG_SNAPPY) +=3D snappy.o
+

=A0hostprogs-y =A0 =A0:=3D gen_crc32table
=A0clean-files =A0 =A0:=3D crc32table.h

lib/snappy.c new file +0 -0
new file mode 100644
index 0000000..0b39e07

lib/snappy.c line 3

Quoted 3 lines
lib/snappy.c new file +3 -0
@@ -0,0 +1,1300 @@
+/*
+ * C port of the snappy compressor from Google.
+ * This is a very fast compressor with comparable compression to lzo=

=2E

lib/snappy.c line 4

Quoted 1 line
lib/snappy.c new file +1 -0
+ * Works best on 64bit little-endian, but should be good on others t=

oo.

lib/snappy.c line 12

Quoted 8 lines
lib/snappy.c new file +8 -0
+ * Ported by Andi Kleen.
+ * Based on snappy 1.0.3 plus some selected changes from SVN.
+ */
+
+/*
+ * Copyright 2005 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or withou=

t

lib/snappy.c line 13

Quoted 1 line
lib/snappy.c new file +1 -0
+ * modification, are permitted provided that the following condition=

s are

lib/snappy.c line 16

Quoted 3 lines
lib/snappy.c new file +3 -0
+ * met:
+ *
+ * =A0 =A0 * Redistributions of source code must retain the above co=

pyright

lib/snappy.c line 19

Quoted 3 lines
lib/snappy.c new file +3 -0
+ * notice, this list of conditions and the following disclaimer.
+ * =A0 =A0 * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following discl=

aimer

lib/snappy.c line 23

Quoted 4 lines
lib/snappy.c new file +4 -0
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * =A0 =A0 * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived f=

rom

lib/snappy.c line 26

Quoted 3 lines
lib/snappy.c new file +3 -0
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTO=

RS

lib/snappy.c line 28

Quoted 2 lines
lib/snappy.c new file +2 -0
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS=

FOR

lib/snappy.c line 29

Quoted 1 line
lib/snappy.c new file +1 -0
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRI=

GHT

lib/snappy.c line 30

Quoted 1 line
lib/snappy.c new file +1 -0
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDEN=

TAL,

lib/snappy.c line 32

Quoted 2 lines
lib/snappy.c new file +2 -0
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF =

USE,

lib/snappy.c line 33

Quoted 1 line
lib/snappy.c new file +1 -0
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON=

ANY

lib/snappy.c line 34

Quoted 1 line
lib/snappy.c new file +1 -0
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TO=

RT

lib/snappy.c line 35

Quoted 1 line
lib/snappy.c new file +1 -0
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE=

USE

lib/snappy.c line 36

Quoted 1 line
lib/snappy.c new file +1 -0
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMA=

GE.

Quoted 61 lines
lib/snappy.c new file +61 -0
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/snappy.h>
+#include <asm/unaligned.h>
+
+#define CRASH_UNLESS(x) BUG_ON(!(x))
+#define CHECK(cond) CRASH_UNLESS(cond)
+#define CHECK_LE(a, b) CRASH_UNLESS((a) <=3D (b))
+#define CHECK_GE(a, b) CRASH_UNLESS((a) >=3D (b))
+#define CHECK_EQ(a, b) CRASH_UNLESS((a) =3D=3D (b))
+#define CHECK_NE(a, b) CRASH_UNLESS((a) !=3D (b))
+#define CHECK_LT(a, b) CRASH_UNLESS((a) < (b))
+#define CHECK_GT(a, b) CRASH_UNLESS((a) > (b))
+
+#define UNALIGNED_LOAD16(_p) get_unaligned((u16 *)(_p))
+#define UNALIGNED_LOAD32(_p) get_unaligned((u32 *)(_p))
+#define UNALIGNED_LOAD64(_p) get_unaligned((u64 *)(_p))
+
+#define UNALIGNED_STORE16(_p, _val) put_unaligned(_val, (u16 *)(_p))
+#define UNALIGNED_STORE32(_p, _val) put_unaligned(_val, (u32 *)(_p))
+#define UNALIGNED_STORE64(_p, _val) put_unaligned(_val, (u64 *)(_p))
+
+#ifdef NDEBUG
+
+#define DCHECK(cond) do {} while(0)
+#define DCHECK_LE(a, b) do {} while(0)
+#define DCHECK_GE(a, b) do {} while(0)
+#define DCHECK_EQ(a, b) do {} while(0)
+#define DCHECK_NE(a, b) do {} while(0)
+#define DCHECK_LT(a, b) do {} while(0)
+#define DCHECK_GT(a, b) do {} while(0)
+
+#else
+
+#define DCHECK(cond) CHECK(cond)
+#define DCHECK_LE(a, b) CHECK_LE(a, b)
+#define DCHECK_GE(a, b) CHECK_GE(a, b)
+#define DCHECK_EQ(a, b) CHECK_EQ(a, b)
+#define DCHECK_NE(a, b) CHECK_NE(a, b)
+#define DCHECK_LT(a, b) CHECK_LT(a, b)
+#define DCHECK_GT(a, b) CHECK_GT(a, b)
+
+#endif
+
+static inline bool is_little_endian(void)
+{
+#ifdef __LITTLE_ENDIAN__
+ =A0 =A0 =A0 return true;
+#endif
+ =A0 =A0 =A0 return false;
+}
+
+static inline int log2_floor(u32 n)
+{
+ =A0 =A0 =A0 return n =3D=3D 0 ? -1 : 31 ^ __builtin_clz(n);
+}
+

lib/snappy.c line 107

Quoted 10 lines
lib/snappy.c new file +10 -0
+static inline int find_lsb_set_non_zero(u32 n)
+{
+ =A0 =A0 =A0 return __builtin_ctz(n);
+}
+
+static inline int find_lsb_set_non_zero64(u64 n)
+{
+ =A0 =A0 =A0 if (sizeof(long) =3D=3D 4) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (n & 0xffffffff)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return __builtin_ctz(n =

& 0xffffffff);

lib/snappy.c line 116

Quoted 9 lines
lib/snappy.c new file +9 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 32 + __builtin_ctz(n >> 32);
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return __builtin_ctzll(n);
+}
+
+#define kmax32 5
+
+/*
+ * Attempts to parse a varint32 from a prefix of the bytes in [ptr,l=

imit-1].

lib/snappy.c line 117

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0Never reads a character at or beyond limit. =A0If a valid/term=

inated varint32

lib/snappy.c line 118

Quoted 1 line
lib/snappy.c new file +1 -0
+ * was found in the range, stores it in *OUTPUT and returns a pointe=

r just

lib/snappy.c line 119

Quoted 1 line
lib/snappy.c new file +1 -0
+ * past the last byte of the varint32. Else returns NULL. =A0On succ=

ess,

lib/snappy.c line 123

Quoted 4 lines
lib/snappy.c new file +4 -0
+ * "result <=3D limit".
+ */
+static inline const char *varint_parse32_with_limit(const char *p,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *l,

lib/snappy.c line 124

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 * OUTPUT)

lib/snappy.c line 126

Quoted 2 lines
lib/snappy.c new file +2 -0
+{
+ =A0 =A0 =A0 const unsigned char *ptr =3D (const unsigned char *)(p)=

;

lib/snappy.c line 127

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 const unsigned char *limit =3D (const unsigned char *)(=

l);

Quoted 23 lines
lib/snappy.c new file +23 -0
+ =A0 =A0 =A0 u32 b, result;
+
+ =A0 =A0 =A0 if (ptr >=3D limit)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+ =A0 =A0 =A0 b =3D *(ptr++);
+ =A0 =A0 =A0 result =3D b & 127;
+ =A0 =A0 =A0 if (b < 128)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done;
+ =A0 =A0 =A0 if (ptr >=3D limit)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+ =A0 =A0 =A0 b =3D *(ptr++);
+ =A0 =A0 =A0 result |=3D (b & 127) << 7;
+ =A0 =A0 =A0 if (b < 128)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done;
+ =A0 =A0 =A0 if (ptr >=3D limit)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+ =A0 =A0 =A0 b =3D *(ptr++);
+ =A0 =A0 =A0 result |=3D (b & 127) << 14;
+ =A0 =A0 =A0 if (b < 128)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done;
+ =A0 =A0 =A0 if (ptr >=3D limit)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+ =A0 =A0 =A0 b =3D *(ptr++);

lib/snappy.c line 160

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 result |=3D (b & 127) << 21;
+ =A0 =A0 =A0 if (b < 128)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done;
+ =A0 =A0 =A0 if (ptr >=3D limit)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+ =A0 =A0 =A0 b =3D *(ptr++);
+ =A0 =A0 =A0 result |=3D (b & 127) << 28;
+ =A0 =A0 =A0 if (b < 16)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done;
+ =A0 =A0 =A0 return NULL; =A0 =A0 =A0 =A0 =A0 =A0/* Value is too lon=

g to be a varint32 */

lib/snappy.c line 167

Quoted 7 lines
lib/snappy.c new file +7 -0
+done:
+ =A0 =A0 =A0 *OUTPUT =3D result;
+ =A0 =A0 =A0 return (const char *)(ptr);
+}
+
+/*
+ * REQUIRES =A0 "ptr" points to a buffer of length sufficient to hol=

d "v".

lib/snappy.c line 168

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0EFFECTS =A0 =A0Encodes "v" into "ptr" and returns a pointer to=

the

Quoted 49 lines
lib/snappy.c new file +49 -0
+ * =A0 =A0 =A0 =A0 =A0 =A0byte just past the last encoded byte.
+ */
+static inline char *varint_encode32(char *sptr, u32 v)
+{
+ =A0 =A0 =A0 /* Operate on characters as unsigneds */
+ =A0 =A0 =A0 unsigned char *ptr =3D (unsigned char *)(sptr);
+ =A0 =A0 =A0 static const int B =3D 128;
+
+ =A0 =A0 =A0 if (v < (1 << 7)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v;
+ =A0 =A0 =A0 } else if (v < (1 << 14)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v >> 7;
+ =A0 =A0 =A0 } else if (v < (1 << 21)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D (v >> 7) | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v >> 14;
+ =A0 =A0 =A0 } else if (v < (1 << 28)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D (v >> 7) | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D (v >> 14) | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v >> 21;
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D (v >> 7) | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D (v >> 14) | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D (v >> 21) | B;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *(ptr++) =3D v >> 28;
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return (char *)(ptr);
+}
+
+struct source {
+ =A0 =A0 =A0 const char *ptr;
+ =A0 =A0 =A0 size_t left;
+};
+
+static inline int available(struct source *s)
+{
+ =A0 =A0 =A0 return s->left;
+}
+
+static inline const char *peek(struct source *s, size_t * len)
+{
+ =A0 =A0 =A0 *len =3D s->left;
+ =A0 =A0 =A0 return s->ptr;
+}
+
+static inline void skip(struct source *s, size_t n)

lib/snappy.c line 227

Quoted 10 lines
lib/snappy.c new file +10 -0
+{
+ =A0 =A0 =A0 s->left -=3D n;
+ =A0 =A0 =A0 s->ptr +=3D n;
+}
+
+struct sink {
+ =A0 =A0 =A0 char *dest;
+};
+
+static inline void append(struct sink *s, const char *data, size_t n=

)

Quoted 9 lines
lib/snappy.c new file +9 -0
+{
+ =A0 =A0 =A0 if (data !=3D s->dest)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 memcpy(s->dest, data, n);
+ =A0 =A0 =A0 s->dest +=3D n;
+}
+
+static inline void *sink_peek(struct sink *s, size_t n)
+{
+ =A0 =A0 =A0 return s->dest;

lib/snappy.c line 246

Quoted 10 lines
lib/snappy.c new file +10 -0
+}
+
+struct writer {
+ =A0 =A0 =A0 char *base;
+ =A0 =A0 =A0 char *op;
+ =A0 =A0 =A0 char *op_limit;
+};
+
+/* Called before decompression */
+static inline void writer_set_expected_length(struct writer *w, size=

_t len)

lib/snappy.c line 258

Quoted 12 lines
lib/snappy.c new file +12 -0
+{
+ =A0 =A0 =A0 w->op_limit =3D w->op + len;
+}
+
+/* Called after decompression */
+static inline bool writer_check_length(struct writer *w)
+{
+ =A0 =A0 =A0 return w->op =3D=3D w->op_limit;
+}
+
+/*
+ * Copy "len" bytes from "src" to "op", one byte at a time. =A0Used =

for

lib/snappy.c line 259

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0handling COPY operations where the input and output regions ma=

y

lib/snappy.c line 270

Quoted 11 lines
lib/snappy.c new file +11 -0
+ * overlap. =A0For example, suppose:
+ * =A0 =A0src =A0 =A0=3D=3D "ab"
+ * =A0 =A0op =A0 =A0 =3D=3D src + 2
+ * =A0 =A0len =A0 =A0=3D=3D 20
+ * After IncrementalCopy(src, op, len), the result will have
+ * eleven copies of "ab"
+ * =A0 =A0ababababababababababab
+ * Note that this does not match the semantics of either memcpy()
+ * or memmove().
+ */
+static inline void incremental_copy(const char *src, char *op, int l=

en)

lib/snappy.c line 279

Quoted 9 lines
lib/snappy.c new file +9 -0
+{
+ =A0 =A0 =A0 DCHECK_GT(len, 0);
+ =A0 =A0 =A0 do {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *op++ =3D *src++;
+ =A0 =A0 =A0 } while (--len > 0);
+}
+
+/*
+ * Equivalent to IncrementalCopy except that it can write up to ten =

extra

lib/snappy.c line 282

Quoted 3 lines
lib/snappy.c new file +3 -0
+ * =A0bytes after the end of the copy, and that it is faster.
+ *
+ * The main part of this loop is a simple copy of eight bytes at a t=

ime until

lib/snappy.c line 283

Quoted 1 line
lib/snappy.c new file +1 -0
+ * we've copied (at least) the requested amount of bytes. =A0However=

, if op and

lib/snappy.c line 284

Quoted 1 line
lib/snappy.c new file +1 -0
+ * src are less than eight bytes apart (indicating a repeating patte=

rn of

lib/snappy.c line 285

Quoted 1 line
lib/snappy.c new file +1 -0
+ * length < 8), we first need to expand the pattern in order to get =

the correct

lib/snappy.c line 286

Quoted 1 line
lib/snappy.c new file +1 -0
+ * results. For instance, if the buffer looks like this, with the ei=

ght-byte

lib/snappy.c line 293

Quoted 7 lines
lib/snappy.c new file +7 -0
+ * <src> and <op> patterns marked as intervals:
+ *
+ * =A0 =A0abxxxxxxxxxxxx
+ * =A0 =A0[------] =A0 =A0 =A0 =A0 =A0 src
+ * =A0 =A0 =A0[------] =A0 =A0 =A0 =A0 op
+ *
+ * a single eight-byte copy from <src> to <op> will repeat the patte=

rn once,

lib/snappy.c line 302

Quoted 9 lines
lib/snappy.c new file +9 -0
+ * after which we can move <op> two bytes without moving <src>:
+ *
+ * =A0 =A0ababxxxxxxxxxx
+ * =A0 =A0[------] =A0 =A0 =A0 =A0 =A0 src
+ * =A0 =A0 =A0 =A0[------] =A0 =A0 =A0 op
+ *
+ * and repeat the exercise until the two no longer overlap.
+ *
+ * This allows us to do very well in the special case of one single =

byte

lib/snappy.c line 303

Quoted 1 line
lib/snappy.c new file +1 -0
+ * repeated many times, without taking a big hit for more general ca=

ses.

lib/snappy.c line 305

Quoted 2 lines
lib/snappy.c new file +2 -0
+ *
+ * The worst case of extra writing past the end of the match occurs =

when

lib/snappy.c line 306

Quoted 1 line
lib/snappy.c new file +1 -0
+ * op - src =3D=3D 1 and len =3D=3D 1; the last copy will read from =

byte positions

lib/snappy.c line 307

Quoted 1 line
lib/snappy.c new file +1 -0
+ * [0..7] and write to [4..11], whereas it was only supposed to writ=

e to

lib/snappy.c line 313

Quoted 6 lines
lib/snappy.c new file +6 -0
+ * position 1. Thus, ten excess bytes.
+ */
+
+#define kmax_increment_copy_overflow =A010
+
+static inline void incremental_copy_fast_path(const char *src, char =

*op,

lib/snappy.c line 314

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 int len)

lib/snappy.c line 317

Quoted 3 lines
lib/snappy.c new file +3 -0
+{
+ =A0 =A0 =A0 while (op - src < 8) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op, UNALIGNED_LOAD64(=

src));

lib/snappy.c line 322

Quoted 5 lines
lib/snappy.c new file +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 len -=3D op - src;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op +=3D op - src;
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 while (len > 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op, UNALIGNED_LOAD64(=

src));

lib/snappy.c line 329

Quoted 7 lines
lib/snappy.c new file +7 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 src +=3D 8;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op +=3D 8;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 len -=3D 8;
+ =A0 =A0 =A0 }
+}
+
+static inline bool writer_append_from_self(struct writer *w, u32 off=

set,

lib/snappy.c line 330

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0u32 len)

lib/snappy.c line 335

Quoted 5 lines
lib/snappy.c new file +5 -0
+{
+ =A0 =A0 =A0 char *op =3D w->op;
+ =A0 =A0 =A0 const int space_left =3D w->op_limit - op;
+
+ =A0 =A0 =A0 if (op - w->base <=3D offset - 1u) =A0 =A0 =A0 =A0/* -1=

u catches offset=3D=3D0 */

lib/snappy.c line 337

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
+ =A0 =A0 =A0 if (len <=3D 16 && offset >=3D 8 && space_left >=3D 16)=

{

lib/snappy.c line 338

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Fast path, used for the majority (70=

-80%) of dynamic

lib/snappy.c line 340

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* invocations. */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op, UNALIGNED_LOAD64(=

op - offset));

lib/snappy.c line 341

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op + 8, UNALIGNED_LOA=

D64(op - offset + 8));

lib/snappy.c line 343

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (space_left >=3D len + kmax_incremen=

t_copy_overflow) {

lib/snappy.c line 344

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 incremental_copy_fast_p=

ath(op - offset, op, len);

lib/snappy.c line 347

Quoted 3 lines
lib/snappy.c new file +3 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (space_left < len) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return =

false;

lib/snappy.c line 349

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 incremental_copy(op - o=

ffset, op, len);

lib/snappy.c line 357

Quoted 8 lines
lib/snappy.c new file +8 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 w->op =3D op + len;
+ =A0 =A0 =A0 return true;
+}
+
+static inline bool writer_append(struct writer *w, const char *ip, u=

32 len,

lib/snappy.c line 358

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0bool=

allow_fast_path)

lib/snappy.c line 362

Quoted 4 lines
lib/snappy.c new file +4 -0
+{
+ =A0 =A0 =A0 char *op =3D w->op;
+ =A0 =A0 =A0 const int space_left =3D w->op_limit - op;
+ =A0 =A0 =A0 if (allow_fast_path && len <=3D 16 && space_left >=3D 1=

6) {

lib/snappy.c line 363

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Fast path, used for the majority (ab=

out 90%) of dynamic

lib/snappy.c line 365

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* invocations. */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op, UNALIGNED_LOAD64(=

ip));

lib/snappy.c line 366

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op + 8, UNALIGNED_LOA=

D64(ip + 8));

lib/snappy.c line 377

Quoted 11 lines
lib/snappy.c new file +11 -0
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (space_left < len)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 memcpy(op, ip, len);
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 w->op =3D op + len;
+ =A0 =A0 =A0 return true;
+}
+
+/*
+ * Any hash function will produce a valid compressed bitstream, but =

a good

lib/snappy.c line 378

Quoted 1 line
lib/snappy.c new file +1 -0
+ * hash function reduces the number of collisions and thus yields be=

tter

lib/snappy.c line 379

Quoted 1 line
lib/snappy.c new file +1 -0
+ * compression for compressible input, and more speed for incompress=

ible

lib/snappy.c line 380

Quoted 1 line
lib/snappy.c new file +1 -0
+ * input. Of course, it doesn't hurt if the hash function is reasona=

bly fast

Quoted 13 lines
lib/snappy.c new file +13 -0
+ * either, as it gets called a lot.
+ */
+static inline u32 hash_bytes(u32 bytes, int shift)
+{
+ =A0 =A0 =A0 u32 kmul =3D 0x1e35a7bd;
+ =A0 =A0 =A0 return (bytes * kmul) >> shift;
+}
+
+static inline u32 hash(const char *p, int shift)
+{
+ =A0 =A0 =A0 return hash_bytes(UNALIGNED_LOAD32(p), shift);
+}
+

lib/snappy.c line 403

Quoted 10 lines
lib/snappy.c new file +10 -0
+/*
+ * Compressed data can be defined as:
+ * =A0 =A0compressed :=3D item* literal*
+ * =A0 =A0item =A0 =A0 =A0 :=3D literal* copy
+ *
+ * The trailing literal sequence has a space blowup of at most 62/60
+ * since a literal of length 60 needs one tag byte + one extra byte
+ * for length information.
+ *
+ * Item blowup is trickier to measure. =A0Suppose the "copy" op copi=

es

lib/snappy.c line 404

Quoted 1 line
lib/snappy.c new file +1 -0
+ * 4 bytes of data. =A0Because of a special check in the encoding co=

de,

lib/snappy.c line 405

Quoted 1 line
lib/snappy.c new file +1 -0
+ * we produce a 4-byte copy only if the offset is < 65536. =A0Theref=

ore

lib/snappy.c line 409

Quoted 4 lines
lib/snappy.c new file +4 -0
+ * the copy op takes 3 bytes to encode, and this type of item leads
+ * to at most the 62/60 blowup for representing literals.
+ *
+ * Suppose the "copy" op copies 5 bytes of data. =A0If the offset is=

big

lib/snappy.c line 410

Quoted 1 line
lib/snappy.c new file +1 -0
+ * enough, it will take 5 bytes to encode the copy op. =A0Therefore =

the

lib/snappy.c line 411

Quoted 1 line
lib/snappy.c new file +1 -0
+ * worst case here is a one-byte literal followed by a five-byte cop=

y.

lib/snappy.c line 424

Quoted 13 lines
lib/snappy.c new file +13 -0
+ * I.e., 6 bytes of input turn into 7 bytes of "compressed" data.
+ *
+ * This last factor dominates the blowup, so the final estimate is:
+ */
+size_t snappy_max_compressed_length(size_t source_len)
+{
+ =A0 =A0 =A0 return 32 + source_len + source_len / 6;
+}
+EXPORT_SYMBOL(snappy_max_compressed_length);
+
+enum {
+ =A0 =A0 =A0 LITERAL =3D 0,
+ =A0 =A0 =A0 COPY_1_BYTE_OFFSET =3D 1, /* 3 bit length + 3 bits of o=

ffset in opcode */

lib/snappy.c line 430

Quoted 6 lines
lib/snappy.c new file +6 -0
+ =A0 =A0 =A0 COPY_2_BYTE_OFFSET =3D 2,
+ =A0 =A0 =A0 COPY_4_BYTE_OFFSET =3D 3
+};
+
+static inline char *emit_literal(char *op,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cons=

t char *literal,

lib/snappy.c line 431

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int =

len, bool allow_fast_path)

lib/snappy.c line 433

Quoted 2 lines
lib/snappy.c new file +2 -0
+{
+ =A0 =A0 =A0 int n =3D len - 1; =A0 =A0 =A0 =A0/* Zero-length litera=

ls are disallowed */

Quoted 9 lines
lib/snappy.c new file +9 -0
+
+ =A0 =A0 =A0 if (n < 60) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Fits in tag byte */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *op++ =3D LITERAL | (n << 2);
+
+/*
+ * The vast majority of copies are below 16 bytes, for which a
+ * call to memcpy is overkill. This fast path can sometimes
+ * copy up to 15 bytes too much, but that is okay in the

lib/snappy.c line 452

Quoted 10 lines
lib/snappy.c new file +10 -0
+ * main loop, since we have a bit to go on for both sides:
+ *
+ * =A0 - The input will always have kInputMarginBytes =3D 15 extra
+ * =A0 =A0 available bytes, as long as we're in the main loop, and
+ * =A0 =A0 if not, allow_fast_path =3D false.
+ * =A0 - The output will always have 32 spare bytes (see
+ * =A0 =A0 MaxCompressedLength).
+ */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (allow_fast_path && len <=3D 16) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op, U=

NALIGNED_LOAD64(literal));

lib/snappy.c line 453

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_STORE64(op + =

8,

lib/snappy.c line 454

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 UNALIGNED_LOAD64(literal + 8));

Quoted 5 lines
lib/snappy.c new file +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return op + len;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Encode in upcoming bytes */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *base =3D op;

lib/snappy.c line 469

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 int count =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op++;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 while (n > 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *op++ =3D n & 0xff;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 n >>=3D 8;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 count++;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK(count >=3D 1);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK(count <=3D 4);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *base =3D LITERAL | ((59 + count) << 2)=

;

lib/snappy.c line 475

Quoted 6 lines
lib/snappy.c new file +6 -0
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 memcpy(op, literal, len);
+ =A0 =A0 =A0 return op + len;
+}
+
+static inline char *emit_copy_less_than64(char *op, int offset, int =

len)

lib/snappy.c line 483

Quoted 8 lines
lib/snappy.c new file +8 -0
+{
+ =A0 =A0 =A0 DCHECK_LE(len, 64);
+ =A0 =A0 =A0 DCHECK_GE(len, 4);
+ =A0 =A0 =A0 DCHECK_LT(offset, 65536);
+
+ =A0 =A0 =A0 if ((len < 12) && (offset < 2048)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 int len_minus_4 =3D len - 4;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK(len_minus_4 < 8); =A0 =A0 =A0 =A0=

/* Must fit in 3 bits */

lib/snappy.c line 485

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *op++ =3D
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 COPY_1_BYTE_OFFSET | ((len_minu=

s_4) << 2) | ((offset >> 8)

lib/snappy.c line 486

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<< 5);

lib/snappy.c line 489

Quoted 3 lines
lib/snappy.c new file +3 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *op++ =3D offset & 0xff;
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *op++ =3D COPY_2_BYTE_OFFSET | ((len - =

1) << 2);

lib/snappy.c line 499

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 put_unaligned_le16(offset, op);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op +=3D 2;
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return op;
+}
+
+static inline char *emit_copy(char *op, int offset, int len)
+{
+ =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0* Emit 64 byte copies but make sure to keep at least=

four bytes

lib/snappy.c line 503

Quoted 4 lines
lib/snappy.c new file +4 -0
+ =A0 =A0 =A0 =A0* reserved
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 while (len >=3D 68) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op =3D emit_copy_less_than64(op, offset=

, 64);

lib/snappy.c line 508

Quoted 5 lines
lib/snappy.c new file +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 len -=3D 64;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0* Emit an extra 60 byte copy if have too much data t=

o fit in

lib/snappy.c line 512

Quoted 4 lines
lib/snappy.c new file +4 -0
+ =A0 =A0 =A0 =A0* one copy
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 if (len > 64) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op =3D emit_copy_less_than64(op, offset=

, 60);

lib/snappy.c line 522

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 len -=3D 60;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Emit remainder */
+ =A0 =A0 =A0 op =3D emit_copy_less_than64(op, offset, len);
+ =A0 =A0 =A0 return op;
+}
+
+/**
+ * snappy_uncompressed_length - return length of uncompressed output=

=2E

lib/snappy.c line 529

Quoted 7 lines
lib/snappy.c new file +7 -0
+ * @start: compressed buffer
+ * @n: length of compressed buffer.
+ * @result: Write the length of the uncompressed output here.
+ *
+ * Returns true when successfull, otherwise false.
+ */
+bool snappy_uncompressed_length(const char *start, size_t n, size_t =

* result)

lib/snappy.c line 533

Quoted 4 lines
lib/snappy.c new file +4 -0
+{
+ =A0 =A0 =A0 u32 v =3D 0;
+ =A0 =A0 =A0 const char *limit =3D start + n;
+ =A0 =A0 =A0 if (varint_parse32_with_limit(start, limit, &v) !=3D NU=

LL) {

Quoted 11 lines
lib/snappy.c new file +11 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *result =3D v;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
+ =A0 =A0 =A0 }
+}
+EXPORT_SYMBOL(snappy_uncompressed_length);
+
+#define kblock_log 15
+#define kblock_size (1 << kblock_log)
+

lib/snappy.c line 554

Quoted 10 lines
lib/snappy.c new file +10 -0
+#define kmax_hash_table_bits 14
+#define kmax_hash_table_size (1 << kmax_hash_table_bits)
+
+/*
+ * Use smaller hash table when input.size() is smaller, since we
+ * fill the table, incurring O(hash table size) overhead for
+ * compression, and if the input is short, we won't need that
+ * many hash table entries anyway.
+ */
+static u16 *get_hash_table(struct snappy_env *env, size_t input_size=

,

lib/snappy.c line 555

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int *table_=

size)

lib/snappy.c line 560

Quoted 5 lines
lib/snappy.c new file +5 -0
+{
+ =A0 =A0 =A0 int htsize =3D 256;
+
+ =A0 =A0 =A0 DCHECK(kmax_hash_table_size >=3D 256);
+ =A0 =A0 =A0 while (htsize < kmax_hash_table_size && htsize < input_=

size)

Quoted 13 lines
lib/snappy.c new file +13 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 htsize <<=3D 1;
+ =A0 =A0 =A0 CHECK_EQ(0, htsize & (htsize - 1));
+ =A0 =A0 =A0 CHECK_LE(htsize, kmax_hash_table_size);
+
+ =A0 =A0 =A0 u16 *table;
+ =A0 =A0 =A0 table =3D env->hash_table;
+
+ =A0 =A0 =A0 *table_size =3D htsize;
+ =A0 =A0 =A0 memset(table, 0, htsize * sizeof(*table));
+ =A0 =A0 =A0 return table;
+}
+
+/*

lib/snappy.c line 583

Quoted 10 lines
lib/snappy.c new file +10 -0
+ * Return the largest n such that
+ *
+ * =A0 s1[0,n-1] =3D=3D s2[0,n-1]
+ * =A0 and n <=3D (s2_limit - s2).
+ *
+ * Does not read *s2_limit or beyond.
+ * Does not read *(s1 + (s2_limit - s2)) or beyond.
+ * Requires that s2_limit >=3D s2.
+ *
+ * Separate implementation for x86_64, for speed. =A0Uses the fact t=

hat

lib/snappy.c line 588

Quoted 5 lines
lib/snappy.c new file +5 -0
+ * x86_64 is little endian.
+ */
+#if defined(__LITTLE_ENDIAN__)
+static inline int find_match_length(const char *s1,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

const char *s2, const char *s2_limit)

lib/snappy.c line 594

Quoted 6 lines
lib/snappy.c new file +6 -0
+{
+ =A0 =A0 =A0 int matched =3D 0;
+
+ =A0 =A0 =A0 DCHECK_GE(s2_limit, s2);
+ =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0* Find out how long the match is. We loop over the d=

ata 64 bits at a

lib/snappy.c line 595

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0* time until we find a 64-bit block that doesn't mat=

ch; then we find

lib/snappy.c line 596

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0* the first non-matching bit and use that to calcula=

te the total

lib/snappy.c line 601

Quoted 5 lines
lib/snappy.c new file +5 -0
+ =A0 =A0 =A0 =A0* length of the match.
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 while (likely(s2 <=3D s2_limit - 8)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (unlikely
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (UNALIGNED_LOAD64(s2) =3D=3D UN=

ALIGNED_LOAD64(s1 + matched))) {

lib/snappy.c line 606

Quoted 5 lines
lib/snappy.c new file +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s2 +=3D 8;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 matched +=3D 8;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* On current (mid-20=

08) Opteron models there

lib/snappy.c line 607

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* is a 3% more effic=

ient code sequence to

lib/snappy.c line 608

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* find the first non=

-matching byte. =A0However,

lib/snappy.c line 609

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* what follows is ~1=

0% better on Intel Core 2

lib/snappy.c line 610

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* and newer, and we =

expect AMD's bsf

lib/snappy.c line 611

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* instruction to imp=

rove.

lib/snappy.c line 614

Quoted 3 lines
lib/snappy.c new file +3 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 x =3D
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_LOAD6=

4(s2) ^ UNALIGNED_LOAD64(s1 +

lib/snappy.c line 615

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 matche=
d);

lib/snappy.c line 616

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int matching_bits =3D f=

ind_lsb_set_non_zero64(x);

lib/snappy.c line 617

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 matched +=3D matching_b=

its >> 3;

Quoted 6 lines
lib/snappy.c new file +6 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return matched;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 while (likely(s2 < s2_limit)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (likely(s1[matched] =3D=3D *s2)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++s2;

lib/snappy.c line 633

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++matched;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return matched;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return matched;
+}
+#else
+static inline int find_match_length(const char *s1,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

const char *s2, const char *s2_limit)

lib/snappy.c line 635

Quoted 2 lines
lib/snappy.c new file +2 -0
+{
+ =A0 =A0 =A0 /* Implementation based on the x86-64 version, above. *=

/

lib/snappy.c line 640

Quoted 5 lines
lib/snappy.c new file +5 -0
+ =A0 =A0 =A0 DCHECK_GE(s2_limit, s2);
+ =A0 =A0 =A0 int matched =3D 0;
+
+ =A0 =A0 =A0 while (s2 <=3D s2_limit - 4 &&
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0UNALIGNED_LOAD32(s2) =3D=3D UNALIGNED_LO=

AD32(s1 + matched)) {

lib/snappy.c line 646

Quoted 6 lines
lib/snappy.c new file +6 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 s2 +=3D 4;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 matched +=3D 4;
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 if (is_little_endian() && s2 <=3D s2_limit - 4) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 x =3D
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNALIGNED_LOAD32(s2) ^ UNALIGNE=

D_LOAD32(s1 + matched);

lib/snappy.c line 647

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 int matching_bits =3D find_lsb_set_non_=

zero(x);

lib/snappy.c line 650

Quoted 3 lines
lib/snappy.c new file +3 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 matched +=3D matching_bits >> 3;
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 while ((s2 < s2_limit) && (s1[matched] =

=3D=3D *s2)) {

lib/snappy.c line 660

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++s2;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++matched;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return matched;
+}
+#endif
+
+/*
+ * For 0 <=3D offset <=3D 4, GetU32AtOffset(UNALIGNED_LOAD64(p), off=

set) will

lib/snappy.c line 661

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0equal UNALIGNED_LOAD32(p + offset). =A0Motivation: On x86-64 h=

ardware we have

lib/snappy.c line 663

Quoted 2 lines
lib/snappy.c new file +2 -0
+ * empirically found that overlapping loads such as
+ * =A0UNALIGNED_LOAD32(p) ... UNALIGNED_LOAD32(p+1) ... UNALIGNED_LO=

AD32(p+2)

lib/snappy.c line 664

Quoted 1 line
lib/snappy.c new file +1 -0
+ * are slower than UNALIGNED_LOAD64(p) followed by shifts and casts =

to u32.

lib/snappy.c line 669

Quoted 5 lines
lib/snappy.c new file +5 -0
+ */
+static inline u32 get_u32_at_offset(u64 v, int offset)
+{
+ =A0 =A0 =A0 DCHECK(0 <=3D offset && offset <=3D 4);
+ =A0 =A0 =A0 return v >> (is_little_endian()? 8 * offset : 32 - 8 * =

offset);

lib/snappy.c line 673

Quoted 4 lines
lib/snappy.c new file +4 -0
+}
+
+/*
+ * Flat array compression that does not emit the "uncompressed lengt=

h"

lib/snappy.c line 679

Quoted 6 lines
lib/snappy.c new file +6 -0
+ * =A0prefix. Compresses "input" string to the "*op" buffer.
+ *
+ * REQUIRES: "input" is at most "kBlockSize" bytes long.
+ * REQUIRES: "op" points to an array of memory that is at least
+ * "MaxCompressedLength(input.size())" in size.
+ * REQUIRES: All elements in "table[0..table_size-1]" are initialize=

d to zero.

lib/snappy.c line 687

Quoted 8 lines
lib/snappy.c new file +8 -0
+ * REQUIRES: "table_size" is a power of two
+ *
+ * Returns an "end" pointer into "op" buffer.
+ * "end - op" is the compressed size of "input".
+ */
+
+static char *compress_fragment(const char *const input,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const si=

ze_t input_size,

lib/snappy.c line 688

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0char *op=

, u16 * table, const int table_size)

lib/snappy.c line 690

Quoted 2 lines
lib/snappy.c new file +2 -0
+{
+ =A0 =A0 =A0 /* "ip" is the input pointer, and "op" is the output po=

inter. */

lib/snappy.c line 699

Quoted 9 lines
lib/snappy.c new file +9 -0
+ =A0 =A0 =A0 const char *ip =3D input;
+ =A0 =A0 =A0 CHECK_LE(input_size, kblock_size);
+ =A0 =A0 =A0 CHECK_EQ(table_size & (table_size - 1), 0);
+ =A0 =A0 =A0 const int shift =3D 32 - log2_floor(table_size);
+ =A0 =A0 =A0 DCHECK_EQ(UINT_MAX >> shift, table_size - 1);
+ =A0 =A0 =A0 const char *ip_end =3D input + input_size;
+ =A0 =A0 =A0 const char *baseip =3D ip;
+ =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0* Bytes in [next_emit, ip) will be emitted as litera=

l bytes. =A0Or

lib/snappy.c line 707

Quoted 8 lines
lib/snappy.c new file +8 -0
+ =A0 =A0 =A0 =A0* =A0[next_emit, ip_end) after the main loop.
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 const char *next_emit =3D ip;
+
+ =A0 =A0 =A0 const int kinput_margin_bytes =3D 15;
+
+ =A0 =A0 =A0 if (likely(input_size >=3D kinput_margin_bytes)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *ip_limit =3D input + input_=

size -

lib/snappy.c line 711

Quoted 4 lines
lib/snappy.c new file +4 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 kinput_margin_bytes;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 next_hash;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 for (next_hash =3D hash(++ip, shift);;)=

{

lib/snappy.c line 712

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_LT(next_emit, ip=

);

lib/snappy.c line 714

Quoted 2 lines
lib/snappy.c new file +2 -0
+/*
+ * The body of this loop calls EmitLiteral once and then EmitCopy on=

e or

lib/snappy.c line 715

Quoted 1 line
lib/snappy.c new file +1 -0
+ * more times. =A0(The exception is that when we're close to exhaust=

ing

lib/snappy.c line 724

Quoted 9 lines
lib/snappy.c new file +9 -0
+ * the input we goto emit_remainder.)
+ *
+ * In the first iteration of this loop we're just starting, so
+ * there's nothing to copy, so calling EmitLiteral once is
+ * necessary. =A0And we only start a new iteration when the
+ * current iteration has determined that a call to EmitLiteral will
+ * precede the next call to EmitCopy (if any).
+ *
+ * Step 1: Scan forward in the input looking for a 4-byte-long match=

=2E

lib/snappy.c line 728

Quoted 4 lines
lib/snappy.c new file +4 -0
+ * If we get close to exhausting the input then goto emit_remainder.
+ *
+ * Heuristic match skipping: If 32 bytes are scanned with no matches
+ * found, start looking only at every other byte. If 32 more bytes a=

re

lib/snappy.c line 730

Quoted 2 lines
lib/snappy.c new file +2 -0
+ * scanned, look at every third byte, etc.. When a match is found,
+ * immediately go back to looking at every byte. This is a small los=

s

lib/snappy.c line 731

Quoted 1 line
lib/snappy.c new file +1 -0
+ * (~5% performance, ~0.1% density) for lcompressible data due to mo=

re

lib/snappy.c line 732

Quoted 1 line
lib/snappy.c new file +1 -0
+ * bookkeeping, but for non-compressible data (such as JPEG) it's a =

huge

lib/snappy.c line 733

Quoted 1 line
lib/snappy.c new file +1 -0
+ * win since the compressor quickly "realizes" the data is incompres=

sible

lib/snappy.c line 736

Quoted 3 lines
lib/snappy.c new file +3 -0
+ * and doesn't bother looking for matches everywhere.
+ *
+ * The "skip" variable keeps track of how many bytes there are since=

the

lib/snappy.c line 737

Quoted 1 line
lib/snappy.c new file +1 -0
+ * last match; dividing it by 32 (ie. right-shifting by five) gives =

the

lib/snappy.c line 742

Quoted 5 lines
lib/snappy.c new file +5 -0
+ * number of bytes to move ahead for each iteration.
+ */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 skip =3D 32;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *next_ip =3D=

ip;

lib/snappy.c line 745

Quoted 3 lines
lib/snappy.c new file +3 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *candidate;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 do {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip =3D =

next_ip;

lib/snappy.c line 746

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 hva=

l =3D next_hash;

lib/snappy.c line 747

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_=

EQ(hval, hash(ip, shift));

lib/snappy.c line 748

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 byt=

es_between_hash_lookups =3D skip++ >> 5;

lib/snappy.c line 749

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next_ip=

=3D ip + bytes_between_hash_lookups;

lib/snappy.c line 750

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (unl=

ikely(next_ip > ip_limit)) {

lib/snappy.c line 751

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 goto emit_remainder;

lib/snappy.c line 753

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next_ha=

sh =3D hash(next_ip, shift);

lib/snappy.c line 754

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 candida=

te =3D baseip + table[hval];

lib/snappy.c line 755

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_=

GE(candidate, baseip);

lib/snappy.c line 756

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_=

LT(candidate, ip);

lib/snappy.c line 758

Quoted 2 lines
lib/snappy.c new file +2 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 table[h=

val] =3D ip - baseip;

lib/snappy.c line 759

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } while (likely(UNALIGN=

ED_LOAD32(ip) !=3D

lib/snappy.c line 760

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 UNALIGNED_LOAD32(candidate)));

lib/snappy.c line 765

Quoted 5 lines
lib/snappy.c new file +5 -0
+
+/*
+ * Step 2: A 4-byte match has been found. =A0We'll later see if more
+ * than 4 bytes match. =A0But, prior to the match, input
+ * bytes [next_emit, ip) are unmatched. =A0Emit them as "literal byt=

es."

lib/snappy.c line 767

Quoted 2 lines
lib/snappy.c new file +2 -0
+ */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_LE(next_emit + 1=

6, ip_end);

lib/snappy.c line 768

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 op =3D emit_literal(op,=

next_emit, ip - next_emit, true);

lib/snappy.c line 773

Quoted 5 lines
lib/snappy.c new file +5 -0
+
+/*
+ * Step 3: Call EmitCopy, and then see if another EmitCopy could
+ * be our next move. =A0Repeat until we find no match for the
+ * input immediately after what was consumed by the last EmitCopy ca=

ll.

lib/snappy.c line 775

Quoted 2 lines
lib/snappy.c new file +2 -0
+ *
+ * If we exit this loop normally then we need to call EmitLiteral ne=

xt,

lib/snappy.c line 776

Quoted 1 line
lib/snappy.c new file +1 -0
+ * though we don't yet know how big the literal will be. =A0We handl=

e that

lib/snappy.c line 777

Quoted 1 line
lib/snappy.c new file +1 -0
+ * by proceeding to the next iteration of the main loop. =A0We also =

can exit

lib/snappy.c line 781

Quoted 4 lines
lib/snappy.c new file +4 -0
+ * this loop via goto if we get close to exhausting the input.
+ */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 input_bytes =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 candidate_bytes =3D=

0;

lib/snappy.c line 788

Quoted 7 lines
lib/snappy.c new file +7 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 do {
+/*
+ * We have a 4-byte match at ip, and no need to emit any
+ * =A0"literal bytes" prior to ip.
+ */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const c=

har *base =3D ip;

lib/snappy.c line 789

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int mat=

ched =3D 4 +

lib/snappy.c line 790

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

find_match_length(candidate + 4, ip + 4,

lib/snappy.c line 791

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip_end);

lib/snappy.c line 792

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip +=3D=

matched;

lib/snappy.c line 793

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int off=

set =3D base - candidate;

lib/snappy.c line 794

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_=

EQ(0, memcmp(base, candidate, matched));

lib/snappy.c line 795

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 op =3D =

emit_copy(op, offset, matched);

lib/snappy.c line 800

Quoted 5 lines
lib/snappy.c new file +5 -0
+/*
+ * We could immediately start working at ip now, but to improve
+ * compression we first update table[Hash(ip - 1, ...)].
+ */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const c=

har *insert_tail =3D ip - 1;

lib/snappy.c line 801

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next_em=

it =3D ip;

lib/snappy.c line 802

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (unl=

ikely(ip >=3D ip_limit)) {

lib/snappy.c line 803

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 goto emit_remainder;

lib/snappy.c line 805

Quoted 2 lines
lib/snappy.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 input_b=

ytes =3D UNALIGNED_LOAD64(insert_tail);

lib/snappy.c line 806

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 pre=

v_hash =3D

lib/snappy.c line 807

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

hash_bytes(get_u32_at_offset

lib/snappy.c line 808

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0(input_bytes, 0), shift);

lib/snappy.c line 809

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 table[p=

rev_hash] =3D ip - baseip - 1;

lib/snappy.c line 810

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 cur=

_hash =3D

lib/snappy.c line 811

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

hash_bytes(get_u32_at_offset

lib/snappy.c line 812

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0(input_bytes, 1), shift);

lib/snappy.c line 813

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 candida=

te =3D baseip + table[cur_hash];

lib/snappy.c line 814

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 candida=

te_bytes =3D UNALIGNED_LOAD32(candidate);

lib/snappy.c line 815

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 table[c=

ur_hash] =3D ip - baseip;

lib/snappy.c line 816

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } while (get_u32_at_off=

set(input_bytes, 1) =3D=3D

lib/snappy.c line 817

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cand=

idate_bytes);

lib/snappy.c line 820

Quoted 3 lines
lib/snappy.c new file +3 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next_hash =3D
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 hash_bytes(get_=

u32_at_offset(input_bytes, 2),

lib/snappy.c line 821

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0shift);

lib/snappy.c line 829

Quoted 8 lines
lib/snappy.c new file +8 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++ip;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+
+emit_remainder:
+ =A0 =A0 =A0 /* Emit the remaining bytes as a literal */
+ =A0 =A0 =A0 if (next_emit < ip_end)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 op =3D emit_literal(op, next_emit, ip_e=

nd - next_emit, false);

lib/snappy.c line 835

Quoted 6 lines
lib/snappy.c new file +6 -0
+
+ =A0 =A0 =A0 return op;
+}
+
+/*
+ * -----------------------------------------------------------------=

------

lib/snappy.c line 836

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0Lookup table for decompression code. =A0Generated by ComputeTa=

ble() below.

lib/snappy.c line 837

Quoted 1 line
lib/snappy.c new file +1 -0
+ * -----------------------------------------------------------------=

------

lib/snappy.c line 840

Quoted 3 lines
lib/snappy.c new file +3 -0
+ */
+
+/* Mapping from i in range [0,4] to a mask to extract the bottom 8*i=

bits */

lib/snappy.c line 849

Quoted 9 lines
lib/snappy.c new file +9 -0
+static const u32 wordmask[] =3D {
+ =A0 =A0 =A0 0u, 0xffu, 0xffffu, 0xffffffu, 0xffffffffu
+};
+
+/*
+ * Data stored per entry in lookup table:
+ * =A0 =A0 =A0 Range =A0 Bits-used =A0 =A0 =A0 Description
+ * =A0 =A0 =A0------------------------------------
+ * =A0 =A0 =A01..64 =A0 0..7 =A0 =A0 =A0 =A0 =A0 =A0Literal/copy len=

gth encoded in opcode byte

lib/snappy.c line 850

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0 =A0 =A00..7 =A0 =A08..10 =A0 =A0 =A0 =A0 =A0 Copy offset enco=

ded in opcode byte / 256

lib/snappy.c line 851

Quoted 1 line
lib/snappy.c new file +1 -0
+ * =A0 =A0 =A00..4 =A0 =A011..13 =A0 =A0 =A0 =A0 =A0Extra bytes afte=

r opcode

lib/snappy.c line 853

Quoted 2 lines
lib/snappy.c new file +2 -0
+ *
+ * We use eight bits for the length even though 7 would have suffice=

d

lib/snappy.c line 856

Quoted 3 lines
lib/snappy.c new file +3 -0
+ * because of efficiency reasons:
+ * =A0 =A0 =A0(1) Extracting a byte is faster than a bit-field
+ * =A0 =A0 =A0(2) It properly aligns copy offset so we do not need a=

<<8

lib/snappy.c line 859

Quoted 3 lines
lib/snappy.c new file +3 -0
+ */
+static const u16 char_table[256] =3D {
+ =A0 =A0 =A0 0x0001, 0x0804, 0x1001, 0x2001, 0x0002, 0x0805, 0x1002,=

0x2002,

lib/snappy.c line 860

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0003, 0x0806, 0x1003, 0x2003, 0x0004, 0x0807, 0x1004,=

0x2004,

lib/snappy.c line 861

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0005, 0x0808, 0x1005, 0x2005, 0x0006, 0x0809, 0x1006,=

0x2006,

lib/snappy.c line 862

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0007, 0x080a, 0x1007, 0x2007, 0x0008, 0x080b, 0x1008,=

0x2008,

lib/snappy.c line 863

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0009, 0x0904, 0x1009, 0x2009, 0x000a, 0x0905, 0x100a,=

0x200a,

lib/snappy.c line 864

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x000b, 0x0906, 0x100b, 0x200b, 0x000c, 0x0907, 0x100c,=

0x200c,

lib/snappy.c line 865

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x000d, 0x0908, 0x100d, 0x200d, 0x000e, 0x0909, 0x100e,=

0x200e,

lib/snappy.c line 866

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x000f, 0x090a, 0x100f, 0x200f, 0x0010, 0x090b, 0x1010,=

0x2010,

lib/snappy.c line 867

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0011, 0x0a04, 0x1011, 0x2011, 0x0012, 0x0a05, 0x1012,=

0x2012,

lib/snappy.c line 868

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0013, 0x0a06, 0x1013, 0x2013, 0x0014, 0x0a07, 0x1014,=

0x2014,

lib/snappy.c line 869

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0015, 0x0a08, 0x1015, 0x2015, 0x0016, 0x0a09, 0x1016,=

0x2016,

lib/snappy.c line 870

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0017, 0x0a0a, 0x1017, 0x2017, 0x0018, 0x0a0b, 0x1018,=

0x2018,

lib/snappy.c line 871

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0019, 0x0b04, 0x1019, 0x2019, 0x001a, 0x0b05, 0x101a,=

0x201a,

lib/snappy.c line 872

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x001b, 0x0b06, 0x101b, 0x201b, 0x001c, 0x0b07, 0x101c,=

0x201c,

lib/snappy.c line 873

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x001d, 0x0b08, 0x101d, 0x201d, 0x001e, 0x0b09, 0x101e,=

0x201e,

lib/snappy.c line 874

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x001f, 0x0b0a, 0x101f, 0x201f, 0x0020, 0x0b0b, 0x1020,=

0x2020,

lib/snappy.c line 875

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0021, 0x0c04, 0x1021, 0x2021, 0x0022, 0x0c05, 0x1022,=

0x2022,

lib/snappy.c line 876

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0023, 0x0c06, 0x1023, 0x2023, 0x0024, 0x0c07, 0x1024,=

0x2024,

lib/snappy.c line 877

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0025, 0x0c08, 0x1025, 0x2025, 0x0026, 0x0c09, 0x1026,=

0x2026,

lib/snappy.c line 878

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0027, 0x0c0a, 0x1027, 0x2027, 0x0028, 0x0c0b, 0x1028,=

0x2028,

lib/snappy.c line 879

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0029, 0x0d04, 0x1029, 0x2029, 0x002a, 0x0d05, 0x102a,=

0x202a,

lib/snappy.c line 880

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x002b, 0x0d06, 0x102b, 0x202b, 0x002c, 0x0d07, 0x102c,=

0x202c,

lib/snappy.c line 881

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x002d, 0x0d08, 0x102d, 0x202d, 0x002e, 0x0d09, 0x102e,=

0x202e,

lib/snappy.c line 882

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x002f, 0x0d0a, 0x102f, 0x202f, 0x0030, 0x0d0b, 0x1030,=

0x2030,

lib/snappy.c line 883

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0031, 0x0e04, 0x1031, 0x2031, 0x0032, 0x0e05, 0x1032,=

0x2032,

lib/snappy.c line 884

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0033, 0x0e06, 0x1033, 0x2033, 0x0034, 0x0e07, 0x1034,=

0x2034,

lib/snappy.c line 885

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0035, 0x0e08, 0x1035, 0x2035, 0x0036, 0x0e09, 0x1036,=

0x2036,

lib/snappy.c line 886

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0037, 0x0e0a, 0x1037, 0x2037, 0x0038, 0x0e0b, 0x1038,=

0x2038,

lib/snappy.c line 887

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0039, 0x0f04, 0x1039, 0x2039, 0x003a, 0x0f05, 0x103a,=

0x203a,

lib/snappy.c line 888

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x003b, 0x0f06, 0x103b, 0x203b, 0x003c, 0x0f07, 0x103c,=

0x203c,

lib/snappy.c line 889

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x0801, 0x0f08, 0x103d, 0x203d, 0x1001, 0x0f09, 0x103e,=

0x203e,

lib/snappy.c line 890

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 0x1801, 0x0f0a, 0x103f, 0x203f, 0x2001, 0x0f0b, 0x1040,=

0x2040

lib/snappy.c line 894

Quoted 4 lines
lib/snappy.c new file +4 -0
+};
+
+struct snappy_decompressor {
+ =A0 =A0 =A0 struct source *reader; =A0/* Underlying source of bytes=

to decompress */

lib/snappy.c line 895

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 const char *ip; =A0 =A0 =A0 =A0 /* Points to next buffe=

red byte */

lib/snappy.c line 896

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 const char *ip_limit; =A0 /* Points just past buffered =

bytes */

lib/snappy.c line 897

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 u32 peeked; =A0 =A0 =A0 =A0 =A0 =A0 /* Bytes peeked fro=

m reader (need to skip) */

lib/snappy.c line 898

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 bool eof; =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Hit end of inp=

ut without an error? */

lib/snappy.c line 899

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 char scratch[5]; =A0 =A0 =A0 =A0/* Temporary buffer for=

peekfast boundaries */

lib/snappy.c line 903

Quoted 4 lines
lib/snappy.c new file +4 -0
+};
+
+static void
+init_snappy_decompressor(struct snappy_decompressor *d, struct sourc=

e *reader)

Quoted 5 lines
lib/snappy.c new file +5 -0
+{
+ =A0 =A0 =A0 d->reader =3D reader;
+ =A0 =A0 =A0 d->ip =3D NULL;
+ =A0 =A0 =A0 d->ip_limit =3D NULL;
+ =A0 =A0 =A0 d->peeked =3D 0;

lib/snappy.c line 918

Quoted 10 lines
lib/snappy.c new file +10 -0
+ =A0 =A0 =A0 d->eof =3D false;
+}
+
+static void exit_snappy_decompressor(struct snappy_decompressor *d)
+{
+ =A0 =A0 =A0 skip(d->reader, d->peeked);
+}
+
+/*
+ * Read the uncompressed length stored at the start of the compresse=

d data.

lib/snappy.c line 923

Quoted 5 lines
lib/snappy.c new file +5 -0
+ * On succcess, stores the length in *result and returns true.
+ * On failure, returns false.
+ */
+static bool read_uncompressed_length(struct snappy_decompressor *d,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0u32 * result)

lib/snappy.c line 926

Quoted 3 lines
lib/snappy.c new file +3 -0
+{
+ =A0 =A0 =A0 DCHECK(d->ip =3D=3D NULL); =A0/*
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Mu=

st not have read anything yet

lib/snappy.c line 927

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Le=

ngth is encoded in 1..5 bytes

lib/snappy.c line 938

Quoted 11 lines
lib/snappy.c new file +11 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 *result =3D 0;
+ =A0 =A0 =A0 u32 shift =3D 0;
+ =A0 =A0 =A0 while (true) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (shift >=3D 32)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t n;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *ip =3D peek(d->reader, &n);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (n =3D=3D 0)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const unsigned char c =3D *(const unsig=

ned char *)(ip);

Quoted 8 lines
lib/snappy.c new file +8 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(d->reader, 1);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 *result |=3D (u32) (c & 0x7f) << shift;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (c < 128) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 shift +=3D 7;
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return true;

lib/snappy.c line 956

Quoted 10 lines
lib/snappy.c new file +10 -0
+}
+
+static bool refill_tag(struct snappy_decompressor *d);
+
+/*
+ * Process the next item found in the input.
+ * Returns true if successful, false on error or end of input.
+ */
+static void decompress_all_tags(struct snappy_decompressor *d,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct =

writer *writer)

lib/snappy.c line 968

Quoted 12 lines
lib/snappy.c new file +12 -0
+{
+ =A0 =A0 =A0 const char *ip =3D d->ip;
+
+ =A0 =A0 =A0 for (;;) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (d->ip_limit - ip < 5) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip =3D ip;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!refill_tag(d))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip =3D d->ip;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const unsigned char c =3D *(const unsig=

ned char *)(ip++);

lib/snappy.c line 971

Quoted 3 lines
lib/snappy.c new file +3 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ((c & 0x3) =3D=3D LITERAL) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 literal_length =3D =

c >> 2;

lib/snappy.c line 972

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (unlikely(literal_le=

ngth >=3D 60)) {

lib/snappy.c line 973

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Long=

literal */

lib/snappy.c line 974

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u=

32 literal_ll =3D literal_length - 59;

lib/snappy.c line 975

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 literal=

_length =3D get_unaligned_le32(ip) &

lib/snappy.c line 976

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 wordmask[literal_ll];

lib/snappy.c line 977

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip +=3D=

literal_ll;

lib/snappy.c line 981

Quoted 4 lines
lib/snappy.c new file +4 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ++literal_length;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 avail =3D d->ip_lim=

it - ip;

lib/snappy.c line 982

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 while (avail < literal_=

length) {

lib/snappy.c line 983

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!wr=

iter_append(writer, ip, avail, false))

lib/snappy.c line 984

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 return;

lib/snappy.c line 985

Quoted 1 line
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 literal=

_length -=3D avail;

Quoted 3 lines
lib/snappy.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(d-=

reader, d->peeked);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t =

n;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip =3D =

peek(d->reader, &n);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 avail =3D=

n;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->peek=

ed =3D avail;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ava=

il =3D=3D 0)

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 return; /* Premature end of input */

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip_l=

imit =3D ip + avail;

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool allow_fast_path =3D=

(avail >=3D 16);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!writer_append(writ=

er, ip, literal_length,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0allow_fast_path))

Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip +=3D literal_length;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 entry =3D cha=

r_table[c];

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 trailer =3D g=

et_unaligned_le32(ip) &

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 wordmas=

k[entry >> 11];

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 length =3D en=

try & 0xff;

Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip +=3D entry >> 11; +
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* copy_offset/256 is=

encoded in bits 8..10.

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* By just fetching t=

hose bits, we get

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* copy_offset (since=

the bit-field starts at

Quoted 3 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* bit 8).
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 copy_offset =3D=

entry & 0x700;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!writer_append_from=

_self(writer,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0copy_offset + trailer,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0length))

lib/snappy.c

Quoted 12 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }

lib/snappy.c new file +9 -0
+}
+
+static bool refill_tag(struct snappy_decompressor *d)
+{
+ =A0 =A0 =A0 const char *ip =3D d->ip;
+
+ =A0 =A0 =A0 if (ip =3D=3D d->ip_limit) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t n;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Fetch a new fragment from the reader=

*/

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(d->reader, d->peeked); /* All peek=

ed bytes are used up */

Quoted 6 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ip =3D peek(d->reader, &n);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->peeked =3D n;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (n =3D=3D 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->eof =3D true;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }

Quoted 8 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip_limit =3D ip + n;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Read the tag character */
+ =A0 =A0 =A0 DCHECK_LT(ip, d->ip_limit);
+ =A0 =A0 =A0 const unsigned char c =3D *(const unsigned char *)(ip);
+ =A0 =A0 =A0 const u32 entry =3D char_table[c];
+ =A0 =A0 =A0 const u32 needed =3D (entry >> 11) + 1; =A0 /* +1 byte =

for 'c' */

lib/snappy.c

Quoted 8 lines

+ =A0 =A0 =A0 DCHECK_LE(needed, sizeof(d->scratch));

lib/snappy.c new file +7 -0
+
+ =A0 =A0 =A0 /* Read more bytes from reader if needed */
+ =A0 =A0 =A0 u32 nbuf =3D d->ip_limit - ip;
+
+ =A0 =A0 =A0 if (nbuf < needed) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Stitch together bytes from ip and =

reader to form the word

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* contents. =A0We store the needed b=

ytes in "scratch". =A0They

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* will be consumed immediately by th=

e caller since we do not

Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* read more than we need.
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 memmove(d->scratch, ip, nbuf);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(d->reader, d->peeked); /* All peek=

ed bytes are used up */

Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->peeked =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 while (nbuf < needed) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t length;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *src =3D pee=

k(d->reader, &length);

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (length =3D=3D 0)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return =

false;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 to_add =3D min_t(u3=

2, needed - nbuf, length);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 memcpy(d->scratch + nbu=

f, src, to_add);

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nbuf +=3D to_add;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(d->reader, to_add)=

;

Quoted 7 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_EQ(nbuf, needed);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip =3D d->scratch;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip_limit =3D d->scratch + needed;
+ =A0 =A0 =A0 } else if (nbuf < 5) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Have enough bytes, but move into s=

cratch so that we do not

Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* read past end of input
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 memmove(d->scratch, ip, nbuf);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(d->reader, d->peeked); /* All peek=

ed bytes are used up */

Quoted 5 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->peeked =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip =3D d->scratch;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip_limit =3D d->scratch + nbuf;
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Pass pointer to buffer returned by r=

eader. */

lib/snappy.c

Quoted 7 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->ip =3D ip;
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 return true;

lib/snappy.c new file +4 -0
+}
+
+static int internal_uncompress(struct source *r,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct w=

riter *writer, u32 max_len)

lib/snappy.c

Quoted 7 lines
lib/snappy.c new file +7 -0
+{
+ =A0 =A0 =A0 struct snappy_decompressor decompressor;
+ =A0 =A0 =A0 u32 uncompressed_len =3D 0;
+
+ =A0 =A0 =A0 init_snappy_decompressor(&decompressor, r);
+
+ =A0 =A0 =A0 if (!read_uncompressed_length(&decompressor, &uncompres=

sed_len))

lib/snappy.c

Quoted 12 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EIO;
+ =A0 =A0 =A0 /* Protect against possible DoS attack */
+ =A0 =A0 =A0 if ((u64) (uncompressed_len) > max_len)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EIO;

lib/snappy.c new file +8 -0
+
+ =A0 =A0 =A0 writer_set_expected_length(writer, uncompressed_len);
+
+ =A0 =A0 =A0 /* Process the entire input */
+ =A0 =A0 =A0 decompress_all_tags(&decompressor, writer);
+
+ =A0 =A0 =A0 exit_snappy_decompressor(&decompressor);
+ =A0 =A0 =A0 return (decompressor.eof && writer_check_length(writer)=

) ? 0 : -EIO;

lib/snappy.c

Quoted 3 lines
lib/snappy.c new file +3 -0
+}
+
+static inline int compress(struct snappy_env *env, struct source *re=

ader,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct sink *wri=

ter)

lib/snappy.c

Quoted 12 lines
lib/snappy.c new file +12 -0
+{
+ =A0 =A0 =A0 int err;
+ =A0 =A0 =A0 size_t written =3D 0;
+ =A0 =A0 =A0 int N =3D available(reader);
+ =A0 =A0 =A0 char ulength[kmax32];
+ =A0 =A0 =A0 char *p =3D varint_encode32(ulength, N);
+
+ =A0 =A0 =A0 append(writer, ulength, p - ulength);
+ =A0 =A0 =A0 written +=3D (p - ulength);
+
+ =A0 =A0 =A0 while (N > 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Get next block to compress (without =

copying if possible) */

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t fragment_size;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *fragment =3D peek(reader, &=

fragment_size);

Quoted 5 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (fragment_size =3D=3D 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -EIO;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int num_to_read =3D min_t(int, N,=

kblock_size);

Quoted 5 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t bytes_read =3D fragment_size; +
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 int pending_advance =3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (bytes_read >=3D num_to_read) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Buffer returned by r=

eader is large enough */

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pending_advance =3D num=

_to_read;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fragment_size =3D num_t=

o_read;

Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+#ifdef SCATHER_GATHER
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 memcpy(env->scratch, fr=

agment, bytes_read);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(reader, bytes_read=

);

Quoted 2 lines

+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 while (bytes_read < num=

_to_read) {

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fragmen=

t =3D peek(reader, &fragment_size);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t =

n =3D

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

min_t(size_t, fragment_size,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 num_to_read - bytes_read);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 memcpy(=

env->scratch + bytes_read, fragment, n);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bytes_r=

ead +=3D n;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(re=

ader, n);

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DCHECK_EQ(bytes_read, n=

um_to_read);

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fragment =3D env->scrat=

ch;

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fragment_size =3D num_t=

o_read;

lib/snappy.c

Quoted 6 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }

lib/snappy.c new file +5 -0
+#endif
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (fragment_size < num_to_read)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EIO;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Get encoding table for compression *=

/

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 int table_size;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 u16 *table =3D get_hash_table(env, num_=

to_read, &table_size);

Quoted 2 lines

+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Compress input_fragment and append t=

o dest */

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int max_output =3D
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 snappy_max_compressed_length(nu=

m_to_read);

lib/snappy.c

Quoted 7 lines
lib/snappy.c new file +7 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *dest;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dest =3D sink_peek(writer, max_output);
+#ifdef SCATHER_GATHER
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!dest) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* Need a scratch buf=

fer for the output,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* because the byte s=

ink doesn't have enough

Quoted 3 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* in one piece.
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dest =3D env->scratch_o=

utput;

Quoted 3 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+#endif
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *end =3D compress_fragment(fragmen=

t, fragment_size,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 dest, table, table_size);

Quoted 23 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 append(writer, dest, end - dest);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 written +=3D (end - dest);

lib/snappy.c new file +21 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 N -=3D num_to_read;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 skip(reader, pending_advance);
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 err =3D 0;
+out:
+ =A0 =A0 =A0 return err;
+}
+
+/**
+ * snappy_compress - Compress a buffer using the snappy compressor.
+ * @env: Preallocated environment
+ * @input: Input buffer
+ * @input_length: Length of input_buffer
+ * @compressed: Output buffer for compressed data
+ * @compressed_length: The real length of the output written here.
+ *
+ * Return 0 on success, otherwise an negative error code.
+ *
+ * The output buffer must be at least

lib/snappy.c

Quoted 10 lines
lib/snappy.c new file +10 -0
+ * snappy_max_compressed_length(input_length) bytes long.
+ *
+ * Requires a preallocated environment from snappy_init_env.
+ * The environment does not keep state over individual calls
+ * of this function, just preallocates the memory.
+ */
+int snappy_compress(struct snappy_env *env,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *input,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size_t input_length,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *compressed, size_t *compr=

essed_length)

Quoted 18 lines
lib/snappy.c new file +18 -0
+{
+ =A0 =A0 =A0 struct source reader =3D {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .ptr =3D input,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .left =3D input_length
+ =A0 =A0 =A0 };
+ =A0 =A0 =A0 struct sink writer =3D {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .dest =3D compressed,
+ =A0 =A0 =A0 };
+ =A0 =A0 =A0 int err =3D compress(env, &reader, &writer);
+
+ =A0 =A0 =A0 /* Compute how many bytes were added */
+ =A0 =A0 =A0 *compressed_length =3D (writer.dest - compressed);
+ =A0 =A0 =A0 return err;
+}
+EXPORT_SYMBOL(snappy_compress);
+
+/**
+ * snappy_uncompress - Uncompress a snappy compressed buffer

lib/snappy.c

Quoted 10 lines
lib/snappy.c new file +10 -0
+ * @compressed: Input buffer with compressed data
+ * @n: length of compressed buffer
+ * @uncompressed: buffer for uncompressed data
+ *
+ * The uncompressed data buffer must be at least
+ * snappy_uncompressed_length(compressed) bytes long.
+ *
+ * Returns true when successfull, otherwise false.
+ */
+bool snappy_uncompress(const char *compressed, size_t n, char *uncom=

pressed)

Quoted 10 lines

+{
+ =A0 =A0 =A0 struct source reader =3D {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .ptr =3D compressed,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .left =3D n
+ =A0 =A0 =A0 };
+ =A0 =A0 =A0 struct writer output =3D {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .base =3D uncompressed,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 .op =3D uncompressed
+ =A0 =A0 =A0 };
+ =A0 =A0 =A0 return internal_uncompress(&reader, &output, 0xffffffff=

);

lib/snappy.c

Quoted 13 lines
lib/snappy.c new file +13 -0
+}
+EXPORT_SYMBOL(snappy_uncompress);
+
+/**
+ * snappy_init_env - Allocate snappy compression environment
+ * @env: Environment to preallocate
+ *
+ * Returns 0 on success, otherwise negative errno.
+ * Must run in process context.
+ */
+int snappy_init_env(struct snappy_env *env)
+{
+ =A0 =A0 =A0 env->hash_table =3D vmalloc(sizeof(u16) * kmax_hash_tab=

le_size);

Quoted 6 lines

+ =A0 =A0 =A0 if (!env->hash_table)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto error;
+#ifdef SCATHER_GATHER
+ =A0 =A0 =A0 env->scratch =3D vmalloc(kblock_size);
+ =A0 =A0 =A0 env->scratch_output =3D
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vmalloc(snappy_max_compressed_length(kb=

lock_size));

Quoted 27 lines

+ =A0 =A0 =A0 if (!env->scratch || !env->scratch_output)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto error;

lib/snappy.c new file +24 -1
+#endif
+ =A0 =A0 =A0 return 0;
+error:
+ =A0 =A0 =A0 snappy_free_env(env);
+ =A0 =A0 =A0 return -ENOMEM;
+}
+EXPORT_SYMBOL(snappy_init_env);
+
+/**
+ * snappy_free_env - Free an snappy compression environment
+ * @env: Environment to free.
+ *
+ * Must run in process context.
+ */
+void snappy_free_env(struct snappy_env *env)
+{
+ =A0 =A0 =A0 vfree(env->hash_table);
+#ifdef SCATHER_GATHER
+ =A0 =A0 =A0 vfree(env->scratch);
+ =A0 =A0 =A0 vfree(env->scratch_output);
+#endif
+ =A0 =A0 =A0 memset(env, 0, sizeof(struct snappy_env));
+}
+EXPORT_SYMBOL(snappy_free_env);
--
Quoted 1 line

1.7.7.4

I've run into one of those x86_64/x86 errors (I think x86_64 has different implicit includes).

(BTW: If you're ever reworking this patch set, I'd like to make an ad hoc request for slightly different names for fs/btrfs/snappy.c and lib/snappy.c)

When building a x86 kernel, I get the following errors:
CC [M] lib/snappy.o
lib/snappy.c: In function 'snappy_init_env':
lib/snappy.c:1268:2: error: implicit declaration of function 'vmalloc'
CC [M] fs/btrfs/free-space-cache.o
lib/snappy.c:1268:18: warning: assignment makes pointer from integer without a cast
lib/snappy.c: In function 'snappy_free_env':
lib/snappy.c:1293:2: error: implicit declaration of function 'vfree' make[1]: *** [lib/snappy.o] Error 1
make: *** [lib] Error 2

The error clears with this patch:

lib/snappy.c +1 -0
index 3848c6c..a25b2a4 100644
@@ -41,6 +41,7 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/snappy.h>
+#include <linux/vmalloc.h>
 #include <asm/unaligned.h>
 
 #define CRASH_UNLESS(x) BUG_ON(!(x))

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH 1/3] Add the snappy-c compressor to lib v2

Quoted 4 lines

(BTW: If you're ever reworking this patch set, I'd like to make an ad hoc request for slightly different names for fs/btrfs/snappy.c and lib/snappy.c)

Why?

Quoted 12 lines

When building a x86 kernel, I get the following errors:
CC [M] lib/snappy.o
lib/snappy.c: In function 'snappy_init_env':
lib/snappy.c:1268:2: error: implicit declaration of function 'vmalloc'
CC [M] fs/btrfs/free-space-cache.o
lib/snappy.c:1268:18: warning: assignment makes pointer from integer without a cast
lib/snappy.c: In function 'snappy_free_env':
lib/snappy.c:1293:2: error: implicit declaration of function 'vfree' make[1]: *** [lib/snappy.o] Error 1
make: *** [lib] Error 2

Quoted 1 line

The error clears with this patch:

Added thanks.

-Andi

#4 lore raw

Re: [PATCH 1/3] Add the snappy-c compressor to lib v2

Quoted 2 lines · Andi Kleen
Quoted 2 lines

(BTW: =A0If you're ever reworking this patch set, I'd like to make a=

n ad

Quoted 6 lines
Quoted 2 lines

hoc request for slightly different names for fs/btrfs/snappy.c and lib/snappy.c)

Why?

It's not a big deal, I just found it confusing at first to see "snappy.c" being a different file in two places.

author
#5 lore raw

PATCH 2/3 BTRFS: Add snappy support v2

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Add support in btrfs for snappy compression. This is generally a faster compressor than LZO (except for higher memory usage) with comparable compression and should imho replace it.

This is based on the lzo code with minor modifications.

This has been tested with various test workloads and also in a real distribution. One challenge with the benchmarks is that a lot of of benchmarks only read/write zeroes, which are a uncommon good case for IO compression. However even with modified workloads that use different patterns gains are seen.

In general snappy performs better with a 64bit CPU, but also generally outperforms LZO on a 32bit Atom system on IO workloads.

The disk space usage is similar to LZO (within 0.2%)

On a distribution boot test on a netboot snappy is about 11.5% faster than LZO or 15.5% faster than an uncompressed btrfs.

Open: implement scatter-gather support and get rid of the temporary buffers. This would only work in some special cases, but should improve performance further by eliminating copies.

Thanks to Jacob Sowles for extensive testing and benchmarking.

v2: Some cleanups, port to latest tree.

---
 fs/btrfs/Kconfig       |    1 +
 fs/btrfs/Makefile      |    2 +-
 fs/btrfs/compression.c |    1 +
 fs/btrfs/compression.h |    1 +
 fs/btrfs/ctree.h       |    9 +-
 fs/btrfs/disk-io.c     |    2 +
 fs/btrfs/ioctl.c       |    4 +
 fs/btrfs/snappy.c      |  432 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/super.c       |    9 +-
 9 files changed, 456 insertions(+), 5 deletions(-)
 create mode 100644 fs/btrfs/snappy.c
fs/btrfs/Kconfig +1 -0
index ecb9fd3..d55df9c 100644
@@ -6,6 +6,7 @@ config BTRFS_FS
 	select ZLIB_DEFLATE
 	select LZO_COMPRESS
 	select LZO_DECOMPRESS
+	select SNAPPY
 	help
 	  Btrfs is a new filesystem with extents, writable snapshotting,
 	  support for multiple devices and many more features.
fs/btrfs/Makefile +1 -1
index c0ddfd2..b93ab52 100644
@@ -8,6 +8,6 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
 	   extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
 	   export.o tree-log.o free-space-cache.o zlib.o lzo.o \
 	   compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \
-	   reada.o backref.o
+	   reada.o backref.o snappy.o
 
 btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
fs/btrfs/compression.c +1 -0
index 14f1c5a..f85f7fd 100644
@@ -730,6 +730,7 @@ static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
 struct btrfs_compress_op *btrfs_compress_op[] = {
 	&btrfs_zlib_compress,
 	&btrfs_lzo_compress,
+	&btrfs_snappy_compress,
 };
 
 int __init btrfs_init_compress(void)
fs/btrfs/compression.h +1 -0
index a12059f..971a425 100644
@@ -79,5 +79,6 @@ struct btrfs_compress_op {
 
 extern struct btrfs_compress_op btrfs_zlib_compress;
 extern struct btrfs_compress_op btrfs_lzo_compress;
+extern struct btrfs_compress_op btrfs_snappy_compress;
 
 #endif
fs/btrfs/ctree.h +6 -3
index 6738503..a06a642 100644
@@ -458,6 +458,7 @@ struct btrfs_super_block {
 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL	(1ULL << 1)
 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS	(1ULL << 2)
 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO	(1ULL << 3)
+#define BTRFS_FEATURE_INCOMPAT_COMPRESS_SNAPPY	(1ULL << 4)
 
 #define BTRFS_FEATURE_COMPAT_SUPP		0ULL
 #define BTRFS_FEATURE_COMPAT_RO_SUPP		0ULL
@@ -465,7 +466,8 @@ struct btrfs_super_block {
 	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
 	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
 	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)
+	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
+	 BTRFS_FEATURE_INCOMPAT_COMPRESS_SNAPPY)
 
 /*
  * A leaf is full of items. offset and size tell us where to find
@@ -621,8 +623,9 @@ enum btrfs_compression_type {
 	BTRFS_COMPRESS_NONE  = 0,
 	BTRFS_COMPRESS_ZLIB  = 1,
 	BTRFS_COMPRESS_LZO   = 2,
-	BTRFS_COMPRESS_TYPES = 2,
-	BTRFS_COMPRESS_LAST  = 3,
+	BTRFS_COMPRESS_SNAPPY = 3,
+	BTRFS_COMPRESS_TYPES = 3,
+	BTRFS_COMPRESS_LAST  = 4,
 };
 
 struct btrfs_inode_item {
fs/btrfs/disk-io.c +2 -0
index f99a099..925dd0a 100644
@@ -2113,6 +2113,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
 	features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
 	if (tree_root->fs_info->compress_type & BTRFS_COMPRESS_LZO)
 		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
+	if (tree_root->fs_info->compress_type & BTRFS_COMPRESS_SNAPPY)
+		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_SNAPPY;
 	btrfs_set_super_incompat_flags(disk_super, features);
 
 	features = btrfs_super_compat_ro_flags(disk_super) &
fs/btrfs/ioctl.c +4 -0
index 5441ff1..2cc2b76 100644
@@ -1173,6 +1173,10 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
 		btrfs_set_super_incompat_flags(disk_super, features);
 	}
+	if (range->compress_type == BTRFS_COMPRESS_SNAPPY) {
+		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_SNAPPY;
+		btrfs_set_super_incompat_flags(disk_super, features);
+	}
 
 	ret = defrag_count;
 
fs/btrfs/snappy.c new file +432 -0

432 lines not on this page · raw message

fs/btrfs/super.c +8 -1
index ae488aa..3240473 100644
@@ -276,6 +276,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
 			} else if (strcmp(args[0].from, "lzo") == 0) {
 				compress_type = "lzo";
 				info->compress_type = BTRFS_COMPRESS_LZO;
+			} else if (strcmp(args[0].from, "snappy") == 0) {
+				compress_type = "snappy";
+				info->compress_type = BTRFS_COMPRESS_SNAPPY;
 			} else {
 				ret = -EINVAL;
 				goto out;
@@ -687,8 +690,12 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
 	if (btrfs_test_opt(root, COMPRESS)) {
 		if (info->compress_type == BTRFS_COMPRESS_ZLIB)
 			compress_type = "zlib";
-		else
+		else if (info->compress_type == BTRFS_COMPRESS_SNAPPY)
+			compress_type = "snappy";
+		else if (info->compress_type == BTRFS_COMPRESS_LZO)
 			compress_type = "lzo";
+		else
+			compress_type = "?";
 		if (btrfs_test_opt(root, FORCE_COMPRESS))
 			seq_printf(seq, ",compress-force=%s", compress_type);
 		else
Signature · 1 line
1.7.7.4
author
#6 lore raw

PATCH 3/3 Add snappy interface to crypto API

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Mainly so that ubifs can use it.

---
 crypto/Kconfig  |    9 +++++
 crypto/Makefile |    1 +
 crypto/snappy.c |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 0 deletions(-)
 create mode 100644 crypto/snappy.c
crypto/Kconfig +9 -0
index e6cfe1a..768943dc 100644
@@ -924,6 +924,15 @@ config CRYPTO_LZO
 	help
 	  This is the LZO algorithm.
 
+config CRYPTO_SNAPPY
+	tristate "Snappy compression algorithm"
+	select CRYPTO_ALGAPI
+	select SNAPPY
+	help
+	  snappy is a faster alternative to the lzo compression algorithm
+	  with comparable compression. It is very fast on 64bit systems, but also
+	  good on 32bit systems. It especially excels at already compressed data.
+
 comment "Random Number Generation"
 
 config CRYPTO_ANSI_CPRNG
crypto/Makefile +1 -0
index f638063..8a0e6c6 100644
@@ -82,6 +82,7 @@ obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
 obj-$(CONFIG_CRYPTO_LZO) += lzo.o
+obj-$(CONFIG_CRYPTO_SNAPPY) += snappy.o
 obj-$(CONFIG_CRYPTO_RNG2) += rng.o
 obj-$(CONFIG_CRYPTO_RNG2) += krng.o
 obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o
crypto/snappy.c new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
1.7.7.4
#7 lore raw
In reply to Andi Kleen

Hi.

Thank you for the job. Could you please share the output of the test=
ing and give us more info about the crypto?

Thank you!
Jaromir

Quoted 12 lines

------------ P=F9vodn=ED zpr=E1va ------------
Od: Andi Kleen <[email protected]>
P=F8edm=ECt: Updated btrfs/crypto snappy interface ready for merging
Datum: 13.1.2012 01:30:21
----------------------------------------
Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.
=20
This version has:
=20
- Ported to latest tree

Quoted 8 lines

- Extensive testing and benchmarking (in its 3.0 based incarnation)
- A few cleanups
- Adds a minor performance improvement
=20
Should be ready for pulling into the btrfs tree now.
The crypto parts have been acked by Herbert.
=20
The following changes since commit 2485a4b610171f4e1c4ab0d05356974779=

5c1bbe:

Quoted 3 lines

=20
Merge branch 'for-linus' of
git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input (2012-01-12 =

12:40:41

Quoted 26 lines

-0800)
=20
are available in the git repository at:
=20
git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc snappy
=20
Andi Kleen (3):
Add the snappy-c compressor to lib v2
BTRFS: Add snappy support v2
Add snappy interface to crypto API
=20

 crypto/Kconfig         |    9 +
 crypto/Makefile        |    1 +
 crypto/snappy.c        |   99 ++++
 fs/btrfs/Kconfig       |    1 +
 fs/btrfs/Makefile      |    2 +-
 fs/btrfs/compression.c |    1 +
 fs/btrfs/compression.h |    1 +
 fs/btrfs/ctree.h       |    9 +-
 fs/btrfs/disk-io.c     |    2 +
 fs/btrfs/ioctl.c       |    4 +
 fs/btrfs/snappy.c      |  432 ++++++++++++++++
 fs/btrfs/super.c       |    9 +-
 include/linux/snappy.h |   26 +
 lib/Kconfig            |    6 +
 lib/Makefile           |    4 +
Quoted 1 line

lib/snappy.c | 1300 ++++++++++++++++++++++++++++++++++++++=

++++++++++

Quoted 10 lines
 16 files changed, 1901 insertions(+), 5 deletions(-)
 create mode 100644 crypto/snappy.c
 create mode 100644 fs/btrfs/snappy.c
 create mode 100644 include/linux/snappy.h
 create mode 100644 lib/snappy.c

=20
-Andi
=20
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=

" in

Quoted 5 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
=20
=20
=20

Jaromir Zdrazil
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
In reply to Andi Kleen
Quoted 3 lines · Andi Kleen

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

Thanks Andi, I've queued this up to a btrfs snappy branch. I put the commits against 3.2 instead of 3.3 though so people could try it out.

The only problem I've hit is that snappy is failing xfstests number 135. It's reproducible on an empty FS. Could you please take a look?

-chris

#9 lore raw
Quoted 11 lines · Chris Mason
Quoted 3 lines · Andi Kleen

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

Thanks Andi, I've queued this up to a btrfs snappy branch. I put the commits against 3.2 instead of 3.3 though so people could try it out.

The only problem I've hit is that snappy is failing xfstests number 135. It's reproducible on an empty FS. Could you please take a look?

It's because decompressing inline extents always fails. I've fixed it and will send the patch out in a new mail thread.

But seems there's bug in lib snappy code, which makes the decompressed data doesn't quite match the original data.

Simply copy a file to a btrfs filesystem with snappy enabled, and clear page cache, and check the file:

* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License (not later!)
+ * License as published by the Free ftwaware Foundation;
+ * version 2.1 of the censnse (not later!)
*
- * This program is distributed in the hope that it will be useful,
+ * is program i is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
+ * GNU Lesser General Publicicenense for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
+ * License along withhis progogram; if not, write to theree e Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

author
#10 lore raw
Quoted 2 lines

It's because decompressing inline extents always fails. I've fixed it and will send the patch out in a new mail thread.

Thanks for fixing.

Quoted 6 lines

But seems there's bug in lib snappy code, which makes the decompressed data doesn't quite match the original data.

Simply copy a file to a btrfs filesystem with snappy enabled, and clear page cache, and check the file:

Hmm weird, I have never seen this. Do you have a reproducer?

The basic compression code is quite well tested, I have a reasonable unit test.

-Andi

#11 lore raw
Quoted 6 lines · Andi Kleen
Quoted 2 lines

It's because decompressing inline extents always fails. I've fixed it and will send the patch out in a new mail thread.

Thanks for fixing.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

But seems there's bug in lib snappy code, which makes the decompressed data doesn't quite match the original data.

Simply copy a file to a btrfs filesystem with snappy enabled, and clear page cache, and check the file:

Hmm weird, I have never seen this. Do you have a reproducer?

Just use some randomly chosen text files. For example:

	# mount -t btrfs -o compress=snappy /dev/xxx /mnt
	# cp -r btrfs-progs-unstable/ /mnt
	# sync
	# echo 3 > /proc/sys/vm/drop_caches
	# diff -Nurp btrfs-progs-unstable /mnt/btrfs-progs-unstable

I've tested on both x86_32 and x86_64.

Quoted 3 lines

The basic compression code is quite well tested, I have a reasonable unit test.

#12 lore raw
In reply to Andi Kleen
Quoted 9 lines · Andi Kleen
Quoted 2 lines

It's because decompressing inline extents always fails. I've fixed it and will send the patch out in a new mail thread.

Thanks for fixing.

Quoted 4 lines

But seems there's bug in lib snappy code, which makes the decompressed data doesn't quite match the original data.

Quoted 8 lines
Quoted 2 lines

Simply copy a file to a btrfs filesystem with snappy enabled, and clear page cache, and check the file:

Hmm weird, I have never seen this. Do you have a reproducer?

The basic compression code is quite well tested, I have a reasonable unit test.

At first I saved emails and patched them in linux-btrfs git tree, and I got weired result. Then I pulled the snappy branch directly, and now nothing is wrong.. Sorry for the noise.

author
#13 lore raw
Quoted 3 lines

At first I saved emails and patched them in linux-btrfs git tree, and I got weired result. Then I pulled the snappy branch directly, and now nothing is wrong.. Sorry for the noise.

np. Thanks for testing.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#14 lore raw
In reply to Andi Kleen
Quoted 3 lines · Andi Kleen

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

Recently the LZ4 method showed up on the real-time compression scene

http://fastcompression.blogspot.com/p/lz4.html (homepage)
http://code.google.com/p/lz4/ (source repo)

it has comparable performance and compression ratio to snappy. Quoting from the source repo main page:

Name            Ratio   C.speed D.speed
LZ4 (r41)       2.08    319     1070
LZO 2.05 1x_1   2.07    318      466
Snappy 1.0.4    2.02    242      683

My own benchmarking confirms that lz4 is has a bit faster decompression, but what is a big difference from snappy is it's memory consumption for compression:
* 32kb for unbounded chunksize
* 16kb for chunksize < 64k (a tuned compression)

No additional memory is needed for decompression in both snappy and lz4. With a minor tweak and chunksize < 4G the context size could be reduced to 16k as well.

There is also LZ4HC, "high compression" mode, which maintains same binary format, but the compression ratio is better.

http://code.google.com/p/lz4hc/

Usecase:
There could be the fast version used transparently and the -hc version could be allowed for the 'fi defrag' command in order to recompress selected files.

LZ4 is written in C and it's BSD, LZ4HC is L-GPL. There is some space for improvements in the code, but as it's good already as it stands now.

david

#15 lore raw
Quoted 9 lines

it has comparable performance and compression ratio to snappy. Quoting from the source repo main page:

Name            Ratio   C.speed D.speed
LZ4 (r41)       2.08    319     1070
LZO 2.05 1x_1   2.07    318      466
Snappy 1.0.4    2.02    242      683

Although there is LessFS's Mark Ruijter :
http://www.lessfs.com/wordpress/?p=684&cpage=1#comment-3114

"On average the speeds appear to be 48% faster then snappy." Sounds promising...

#17 lore raw
Quoted 9 lines · Hugo Chevrain
Quoted 9 lines
Quoted 1 line · evergreen

Although there is LessFS's Mark Ruijter :
http://www.lessfs.com/wordpress/?p=684&cpage=1#comment-3114

"On average the speeds appear to be 48% faster then snappy." Sounds promising...

Quoted 6 lines
Quoted 1 line

--

Well, it seems that the performance is really good. Apparently, LZ4 has displaced Snappy as speed champion for LessFS.

http://www.lessfs.com/wordpress/?p=688

I'm preparing a LZ4 on top of Chris' snappy branch to have some testbed for comparing and benchmarking. I'll send it to list after a few tests.

david

#18 lore raw
In reply to Andi Kleen
Quoted 3 lines · Andi Kleen

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

I'd like to note that the LZO version in the current Linux kernel is rather outdated - it seems to be based on the 2005 release.

In fact the latest version LZO 2.06 does compress both slightly faster and better than snappy 1.0.4 when benchmarking the Calgary and Silesia compression corpus (tested with gcc 4.6 on Nehalem & Sandy Bridge).

Furthermore please be aware that from a pure compression point of view snappy et al. are very close cousins of LZO (strictly byte-aligned LZ77) that mainly differ in implementation issues like using a table to number of branches - and indeed similar optimizations could be applied to any version.

I'm not sure if there is an official kernel maintainer of LZO, but I'd offer to assist you updating to the latest version and eliminating any possible performance issues.

Cheers,
Markus

Signature · 1 line
Markus Oberhumer, <[email protected]>, http://www.oberhumer.com/
#19 lore raw

ANN: linux-kernel-lzo-2.06.20120123 - update LZO to v2.06

Hi,

I've prepared a small package that updates the LZO version in the Linux kernel to LZO v2.06.

Please get it from:

http://www.oberhumer.com/opensource/lzo/download/Testing/linux-kernel-lzo-2.06.20120123.tar.gz

As stated in the README, its main purpose is to allow easy benchmarking of the latest LZO versions - these do feature some nice speed improvements, and while I have done a lot of synthetic benchmarking I'm really very curious and appreciate feedback on "real-world" performance numbers like usage in btrfs and zram.

Share and enjoy,
Markus

http://www.oberhumer.com/opensource/lzo/

Quoted 21 lines · Markus F.X.J. Oberhumer
Quoted 3 lines · Andi Kleen

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

I'd like to note that the LZO version in the current Linux kernel is rather outdated - it seems to be based on the 2005 release.

In fact the latest version LZO 2.06 does compress both slightly faster and better than snappy 1.0.4 when benchmarking the Calgary and Silesia compression corpus (tested with gcc 4.6 on Nehalem & Sandy Bridge).

Furthermore please be aware that from a pure compression point of view snappy et al. are very close cousins of LZO (strictly byte-aligned LZ77) that mainly differ in implementation issues like using a table to number of branches - and indeed similar optimizations could be applied to any version.

I'm not sure if there is an official kernel maintainer of LZO, but I'd offer to assist you updating to the latest version and eliminating any possible performance issues.

Signature · 1 line
Markus Oberhumer, <[email protected]>, http://www.oberhumer.com/
#20 lore raw

Re: ANN: linux-kernel-lzo-2.06.20120123 - update LZO to v2.06

Hi Markus,

Thanks for the patches!

Quoted 7 lines · Markus F.X.J. Oberhumer

Hi,

I've prepared a small package that updates the LZO version in the Linux kernel to LZO v2.06.

Please get it from:

Quoted 8 lines

http://www.oberhumer.com/opensource/lzo/download/Testing/linux-kernel-lzo-2.06.20120123.tar.gz

As stated in the README, its main purpose is to allow easy benchmarking of the latest LZO versions - these do feature some nice speed improvements, and while I have done a lot of synthetic benchmarking I'm really very curious and appreciate feedback on "real-world" performance numbers like usage in btrfs and zram.

I will soon integrate them with zram and get some performance numbers.

Thanks,
Nitin

Quoted 26 lines

http://www.oberhumer.com/opensource/lzo/

Quoted 21 lines · Markus F.X.J. Oberhumer
Quoted 3 lines · Andi Kleen

Here's a slightly updated version of the BTRFS snappy interface. snappy is a faster compression algorithm that provides similar compression as LZO, but generally better performance.

I'd like to note that the LZO version in the current Linux kernel is rather outdated - it seems to be based on the 2005 release.

In fact the latest version LZO 2.06 does compress both slightly faster and better than snappy 1.0.4 when benchmarking the Calgary and Silesia compression corpus (tested with gcc 4.6 on Nehalem & Sandy Bridge).

Furthermore please be aware that from a pure compression point of view snappy et al. are very close cousins of LZO (strictly byte-aligned LZ77) that mainly differ in implementation issues like using a table to number of branches - and indeed similar optimizations could be applied to any version.

I'm not sure if there is an official kernel maintainer of LZO, but I'd offer to assist you updating to the latest version and eliminating any possible performance issues.

author
#21 lore raw

Re: ANN: linux-kernel-lzo-2.06.20120123 - update LZO to v2.06

In reply to Markus F.X.J. Oberhumer
Quoted 4 lines · Markus F.X.J. Oberhumer

Hi,

I've prepared a small package that updates the LZO version in the Linux kernel to LZO v2.06.

I ran benchmarks on the new miniLZO and LZ4 on 64bit. LZ4 is generally slower than snappy/lzo in the micro benchmarks. The new LZO is better than the old one, but still loses to snappy most of the time (but often by very small amounts only)

Will be worth checking the new LZO will the full distribution boot test.

I agree it's definitely a good idea to update the kernel version. However I must say it would be a major project to bring it up to kernel coding standards.

snappy is still interesting, but much less so than it was before.

-Andi

#22 lore raw

Re: ANN: linux-kernel-lzo-2.06.20120123 - update LZO to v2.06

Quoted 2 lines · Andi Kleen

I ran benchmarks on the new miniLZO and LZ4 on 64bit. LZ4 is generally slower than snappy/lzo in the micro benchmarks.

And the reason why you measured worse speed for LZ4 although (AFAICT) everybody else's measurements claim the opposite is quite simple:
likely due to a copy&paste error you did not benchmark LZ4 at all:

https://github.com/andikleen/snappy-c/blob/master/glue.c#L282

274 void test_lz4(char *map, size_t size, char *fn) 275 {

276         int i;
277         int err;
278         size_t outlen = size * 2;
279         char *out = xmalloc(outlen);
280         char *buf2 = xmalloc(size);
281
282         BENCH(fastlz, "lz4", fn, NULL);
                  ^^^^^^

283
284 free(out);
285 free(buf2);
286 }

(LZ4 is on it's track towards kernel)

david

#23 lore raw

ANNOUNCE: linux-kernel-lzo-20120716 - update LZO

In reply to Markus F.X.J. Oberhumer

Hi all,

I finally have prepared a small package that updates the LZO version in the Linux kernel. Please get it from:

http://www.oberhumer.com/opensource/lzo/download/Testing/linux-kernel-lzo-20120716.tar.gz

As stated in the README this version is significantly faster (typically more than 2 times faster!) than the current version, has been thoroughly tested on x86_64/i386/powerpc platforms and is intended to get included into the official Linux 3.6 or 3.7 release.

I encourage all compression users to test and benchmark this new version, and I also would ask some official LZO maintainer to convert the updated source files into a GIT commit and possibly push it to Linus or linux-next.

Share and enjoy,
Markus

Signature · 1 line
Markus Oberhumer, <[email protected]>, http://www.oberhumer.com/
#24 lore raw

Re: ANNOUNCE: linux-kernel-lzo-20120716 - update LZO

Hi!

Quoted 3 lines · Markus F.X.J. Oberhumer

I encourage all compression users to test and benchmark this new version, and I also would ask some official LZO maintainer to convert the updated source files into a GIT commit and possibly push it to Linus or linux-next.

You could also send a patch yourself. :-)

Signature · 2 lines
Thanks,
//richard