decompressor: Add LZ4 decompressor module

Date	Tue, 26 Feb 2013 15:24:27 +0900

This patch adds support for LZ4 decompression in the Linux Kernel.
LZ4 Decompression APIs for kernel are based on LZ4 implementation
by Yann Collet.

LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
LZ4 source repository : http://code.google.com/p/lz4/

Signed-off-by: Kyungsik Lee <kyungsik.lee@lge.com>

v2:
- Clean up code
- Enable unaligned access for ARM v6 and above with
  CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- Add lz4_decompress() for faster decompression with
  uncompressed output size

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 7439058d1ae075bc029ab8453c25cc0b3e25b3e1)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
lib: Add support for LZ4-compressed kernel

Date	Tue, 26 Feb 2013 15:24:28 +0900

This patch adds support for extracting LZ4-compressed kernel images,
as well as LZ4-compressed ramdisk images in the kernel boot process.

This depends on the patch below
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee <kyungsik.lee@lge.com>

v2:
- Clean up code
- Use lz4_decompress() for LZ4-compressed kernel during boot-process

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 71949ca886cd653c3d29bd9c41ca808f087ed008)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
lib: Add lz4 compressor module

From	Chanho Min <>

This patch adds support for LZ4 compression in the Linux Kernel.
LZ4 Compression APIs for kernel are based on LZ4 implementation
by Yann Collet and changed with kernel coding style.

LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
LZ4 source repository : http://code.google.com/p/lz4/
svn revision : r90

Two APIs are added:
lz4_compress() support basic lz4 compression whereas lz4hc_compress() support
high compression or CPU performance get lower but compression ratio get higher.
Also, we require the pre-allocated working memory with the defined size and
destination buffer must be allocated with the size of lz4_compressbound.

Signed-off-by: Chanho Min <chanho.min@lge.com>

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 116d3278f6e0b271439be2e2e63912435328483d)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
crypto: Add lz4 Cryptographic API

From	Chanho Min <>

This patch adds support for lz4 and lz4hc compression algorithm
using the lib/lz4/* codebase.
Signed-off-by: Chanho Min <chanho.min@lge.com>

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 504eda185e66610b660c1db894edbba863eeb4c4)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
lib/lz4/lz4_compress: fix macro usage error

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 0acdecfdc74019c30c5649038a8fe82480f21724)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>

Change-Id: Ifee8e3c84769e494de1c03e3c194151ecb55e38c
LZ4: compression/decompression signedness mismatch (v2)

LZ4 compression and decompression functions require different
in signedness input/output parameters: unsigned char for
compression and signed char for decompression.

Change decompression API to require "(const) unsigned char *".

v2: minor coding style fix.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit dce4a756022b13adf0033c724b0ee0b8016b62de)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
staging: zram: add Crypto API support

Date    Tue, 30 Jul 2013 14:30:48 +0200

Current version of zram does not allow any substitution of a default
compression algorithm. Therefore, I decided to change the existing
implementation of page compression by adding Crypto API compability.

All direct calls to lzo1x compression/decompression methods are now
replaced by calls consistent with Crypto. Also, I removed "workmem"
field from struct zram_meta, as it was there for lzo1x purposes only
and is no longer needed. Finally, I added a set of functions required
by Crypto API to work properly.

In order to substitute the default algorithm (lzo), change the value
of zram.compressor module parameter to a proper name (e.g. lz4).

Signed-off-by: Piotr Sarna <p.sarna@partner.samsung.com>
Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>

backported to Linux 3.4 by faux123

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 5457928a87a4bdc32316990a4a8d839390c38896)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
staging: zram: add per-cpu support to Crypto

Date	Tue, 30 Jul 2013 14:30:49 +0200

Since original zram code did not implement any per-cpu operations,
my previous patch (staging: zram: add Crypto API support) did not
include them either.

This patch complements the first one with per-cpu support for Crypto,
allocating tfms buffer separately for each online processor.
Changes are based on zswap and zcache per-cpu code.

Basic tests (concurrent writing several 10-40MB chunks to zram) performed
on an ARM-based EXYNOS4412 Quad-Core showed that per-cpu code provides
noticeable time saving, ranging between 30-40% for LZO and LZ4 compressors.
Sample data (LZO): writing 160MB, 40MB per thread took 0.60s with per-cpu
code included and approximately 0.80s without per-cpu support.

Signed-off-by: Piotr Sarna <p.sarna@partner.samsung.com>
Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>

backported to Linux 3.4 by faux123
Signed-off-by: Paul Reioux <reioux@gmail.com>

(cherry picked from commit 483a1db721ef56475bfe882cd2711a1755626dac)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
zram_drv: switch default compressor to new lz4

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit cf6268eadf8df3841e2014c2646ff6e875a35fae)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
zcache-main.c: use MACRO define instead of hardcoded default of lzo

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 0957aeebe16dc05c3113774c2f26f207a6b52cf9)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>
zcache-main: switch to lz4 as default

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 95be30e37755a46fc27a96e849524c60311b9c1b)
Signed-off-by: Hieu Phan <aznrice2k4@gmail.com>