lib/lzo: performance improvements
Subsystems (4)
v2 cover lib/lzo: performance improvements
This patch series introduces performance improvements for lzo.
The previous version of this patchset is here:
https://lkml.org/lkml/2018/11/21/625
This version tidies up the ifdefs as per Christoph's comment (although certainly more could be done, this is at least a bit more consistent with normal kernel coding style).
Quoted 11 lines · Sergey Senozhatsky
Quoted 5 lines
The graph below shows the weighted round-trip throughput of lzo, lz4 and lzo-rle, for randomly generated 4k chunks of data with varying levels of entropy. (To calculate weighted round-trip throughput, compression performance is emphasised to reflect the fact that zram does around 2.25x more compression than decompression.
Right. The number is data dependent. Not all swapped out pages can be compressed; compressed pages that end up being >=
zs_huge_class_size()are considered incompressible and stored as it.I'd say that on my setups around 50-60% of pages are incompressible.
So, just to give a bit more detail: the test setup was a Samsung Chromebook Pro, cycling through 80 tabs in Chrome. With lzo-rle, only 5% of pages increased in size, and 90% of pages compress to 75% of original size (or better). Mean compression ratio was 41%. Importantly for lzo-rle, there are a lot of low-entropy pages where it can do well:
in total about 20% of the data is zeros forming part of a run of 4 or more bytes.
As a quick summary of the impact of these patches on bigger chunks of data, I've compared the performance of four different variants of lzo on two large (~40 MB) files. The numbers show round-trip throughput in MB/s:
Variant | Low-entropy | High-entropy Current lzo | 242 | 157 Arm opts | 290 | 159 RLE | 876 | 151 Arm opts + RLE | 1150 | 181
So both the Arm optimisations (8,16-byte copy & CTZ patches), and the RLE implementation make a significant contribution to the overall performance uplift.
PATCH v2 1/7 lib/lzo: tidy-up ifdefs
Modify the ifdefs in lzodefs.h to be more consistent with normal kernel macros (e.g., change __aarch64__ to CONFIG_ARM64).
--- lib/lzo/lzodefs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/lzo/lzodefs.h +4 -4
@@ -15,7 +15,7 @@#define COPY4 (dst, src) \ put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst)) -#if defined(__x86_64__) +#if defined(CONFIG_X86_64 )#define COPY8 (dst, src) \ put_unaligned(get_unaligned((const u64 *)(src)), (u64 *)(dst))#else
@@ -25,12 +25,12 @@#if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)#error "conflicting endian definitions" -#elif defined(__x86_64__) +#elif defined(CONFIG_X86_64 )#define LZO_USE_CTZ64 1#define LZO_USE_CTZ32 1 -#elif defined(__i386__) || defined(__powerpc__) +#elif defined(CONFIG_X86 ) || defined(CONFIG_PPC )#define LZO_USE_CTZ32 1 -#elif defined(__arm__) && (__LINUX_ARM_ARCH__ >=5 ) +#elif defined(CONFIG_ARM ) && (__LINUX_ARM_ARCH__ >=5 )#define LZO_USE_CTZ32 1#endif
Signature · 1 line
2.16.4
PATCH v2 2/7 lib/lzo: clean-up by introducing COPY16
In reply to Dave RodgmanFrom: Matt Sealey <[email protected]>
Most compilers should be able to merge adjacent loads/stores of sizes which are less than but effect a multiple of a machine word size (in effect a memcpy() of a constant amount). However the semantics of the macro are that it just does the copy, the pointer increment is in the code, hence we see
*a = *b
a += 8
b += 8
*a = *b
a += 8
b += 8This introduces a dependency between the two groups of statements which seems to defeat said compiler optimizers and generate some very strange sequences of addition and subtraction of address offsets (i.e. it is overcomplicated).
Since COPY8 is only ever used to copy amounts of 16 bytes (in pairs), just define COPY16 as COPY8,COPY8. We leave the definition to preserve the need to do unaligned accesses to machine-sized words per the original code intent, we just don't use it in the code proper.
COPY16 then gives us code like:
*a = *b
*(a+8) = *(b+8)
a += 16
b += 16This seems to allow compilers to generate much better code by using base register writeback or simply positively incrementing offsets which seems to positively affect performance. It is, at least, fewer instructions to do the same job.
--- lib/lzo/lzo1x_compress.c | 9 +++------ lib/lzo/lzo1x_decompress_safe.c | 18 ++++++------------ lib/lzo/lzodefs.h | 3 +++ 3 files changed, 12 insertions(+), 18 deletions(-)
lib/lzo/lzo1x_compress.c +3 -6
@@ -60,8 +60,7 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len, op += t; }else if (t <=16 ) { *op++ = (t -3 ); -COPY8 (op, ii); -COPY8 (op +8 , ii +8 ); +COPY16 (op, ii); op += t; }else {if (t <=18 ) {
@@ -76,8 +75,7 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len, *op++ = tt; } do { - COPY8(op, ii); - COPY8(op + 8, ii + 8); + COPY16(op, ii); op += 16; ii += 16; t -= 16;
@@ -255,8 +253,7 @@ int lzo1x_1_compress(const unsigned char *in, size_t in_len, *op++ = tt; } if (t >= 16) do { - COPY8(op, ii); - COPY8(op + 8, ii + 8); + COPY16(op, ii); op += 16; ii += 16; t -= 16;
lib/lzo/lzo1x_decompress_safe.c +6 -12
@@ -86,12 +86,9 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,const unsigned char *ie = ip + t;unsigned char *oe = op + t;do { -COPY8 (op, ip); - op +=8 ; - ip +=8 ; -COPY8 (op, ip); - op +=8 ; - ip +=8 ; +COPY16 (op, ip); + op +=16 ; + ip +=16 ; }while (ip < ie); ip = ie; op = oe;
@@ -187,12 +184,9 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,unsigned char *oe = op + t;if (likely (HAVE_OP (t +15 ))) {do { -COPY8 (op, m_pos); - op +=8 ; - m_pos +=8 ; -COPY8 (op, m_pos); - op +=8 ; - m_pos +=8 ; +COPY16 (op, m_pos); + op +=16 ; + m_pos +=16 ; }while (op < oe); op = oe;if (HAVE_IP (6 )) {
lib/lzo/lzodefs.h +3 -0
@@ -23,6 +23,9 @@ COPY4(dst, src); COPY4((dst) + 4, (src) + 4)#endif +#define COPY16 (dst, src) \ + do { COPY8(dst, src); COPY8((dst) + 8, (src) + 8); } while (0) +#if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)#error "conflicting endian definitions"#elif defined(CONFIG_X86_64 )
Signature · 1 line
2.16.4
Re: [PATCH 2/7] lib/lzo: clean-up by introducing COPY16
Quoted 5 lines · On Tue, 27 Nov 2018 16:19:31 +0000 Dave Rodgman <[email protected]> wrote:
From: Matt Sealey <[email protected]>
...
Signed-off-by Matt Sealey <[email protected]>
Several of the From:Matt patches were missing your Signed-off-by:. I added it.
[patch 5/7] had the signoffs in an inappropriate order - I switched them.
PATCH v2 3/7 lib/lzo: enable 64-bit CTZ on Arm
In reply to Dave RodgmanFrom: Matt Sealey <[email protected]>
ARMv6 Thumb state introduced an RBIT instruction which, combined with CLZ as present in ARMv5, introduces an extremely fast path for counting trailing zeroes.
Enable the use of the GCC builtin for this on ARMv6+ with CONFIG_THUMB2_KERNEL to ensure we get the 'new' instruction usage.
We do not bother enabling LZO_USE_CTZ64 support for ARMv5 as the builtin code path does the same thing as the LZO_USE_CTZ32 code, only with more register pressure.
--- lib/lzo/lzodefs.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/lzo/lzodefs.h +6 -1
@@ -33,9 +33,14 @@#define LZO_USE_CTZ32 1#elif defined(CONFIG_X86 ) || defined(CONFIG_PPC )#define LZO_USE_CTZ32 1 -#elif defined(CONFIG_ARM ) && (__LINUX_ARM_ARCH__ >=5 ) +#elif defined(CONFIG_ARM ) +#if (__LINUX_ARM_ARCH__ >=5 )#define LZO_USE_CTZ32 1#endif +#if (__LINUX_ARM_ARCH__ >=6 ) && defined(CONFIG_THUMB2_KERNEL ) +#define LZO_USE_CTZ64 1 +#endif +#endif #define M1_MAX_OFFSET 0x0400#define M2_MAX_OFFSET 0x0800
Signature · 1 line
2.16.4
PATCH v2 4/7 lib/lzo: 64-bit CTZ on arm64
In reply to Dave RodgmanFrom: Matt Sealey <[email protected]>
LZO leaves some performance on the table by not realising that arm64 can optimize count-trailing-zeros bit operations.
Add CONFIG_ARM64 to the checked definitions alongside CONFIG_X86_64 to enable the use of rbit/clz instructions on full 64-bit quantities.
--- lib/lzo/lzodefs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/lzo/lzodefs.h +1 -1
@@ -28,7 +28,7 @@#if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)#error "conflicting endian definitions" -#elif defined(CONFIG_X86_64 ) +#elif defined(CONFIG_X86_64 ) || defined(CONFIG_ARM64 )#define LZO_USE_CTZ64 1#define LZO_USE_CTZ32 1#elif defined(CONFIG_X86 ) || defined(CONFIG_PPC )
Signature · 1 line
2.16.4
PATCH v2 5/7 lib/lzo: fast 8-byte copy on arm64
In reply to Dave RodgmanFrom: Matt Sealey <[email protected]>
Enable faster 8-byte copies on arm64.
--- lib/lzo/lzodefs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/lzo/lzodefs.h +1 -1
@@ -15,7 +15,7 @@#define COPY4 (dst, src) \ put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst)) -#if defined(CONFIG_X86_64 ) +#if defined(CONFIG_X86_64 ) || defined(CONFIG_ARM64 )#define COPY8 (dst, src) \ put_unaligned(get_unaligned((const u64 *)(src)), (u64 *)(dst))#else
Signature · 1 line
2.16.4
PATCH v2 6/7 lib/lzo: implement run-length encoding
In reply to Dave RodgmanWhen using zram, we frequently encounter long runs of zero bytes. This adds a special case which identifies runs of zeros and encodes them using run-length encoding.
This is faster for both compression and decompresion. For high-entropy data which doesn't hit this case, impact is minimal.
Compression ratio is within a few percent in all cases.
This modifies the bitstream in a way which is backwards compatible (i.e., we can decompress old bitstreams, but old versions of lzo cannot decompress new bitstreams).
--- Documentation/lzo.txt | 35 ++++++++++++--- include/linux/lzo.h | 2 +- lib/lzo/lzo1x_compress.c | 98 ++++++++++++++++++++++++++++++++++++----- lib/lzo/lzo1x_decompress_safe.c | 75 +++++++++++++++++++++---------- lib/lzo/lzodefs.h | 12 ++++- 5 files changed, 180 insertions(+), 42 deletions(-)
Documentation/lzo.txt +28 -7
@@ -78,16 +78,30 @@ Description is an implementation design choice independent on the algorithm or encoding. +Versions + +0: Original version +1: LZO-RLE + +Version 1 of LZO implements an extension to encode runs of zeros using run +length encoding. This improves speed for data with many zeros, which is a +common case for zram. This modifies the bitstream in a backwards compatible way +(v1 can correctly decompress v0 compressed data, but v0 cannot read v1 data). + Byte sequences ============== First byte encoding:: - 0..17 : follow regular instruction encoding, see below. It is worth - noting that codes 16 and 17 will represent a block copy from - the dictionary which is empty, and that they will always be + 0..16 : follow regular instruction encoding, see below. It is worth + noting that code 16 will represent a block copy from the + dictionary which is empty, and that it will always be invalid at this place. + 17 : bitstream version. If the first byte is 17, the next byte + gives the bitstream version. If the first byte is not 17, + the bitstream version is 0. + 18..21 : copy 0..3 literals state = (byte - 17) = 0..3 [ copy <state> literals ] skip byte
@@ -140,6 +154,11 @@ Byte sequences state = S (copy S literals after this block) End of stream is reached if distance == 16384 + In version 1, this instruction is also used to encode a run of zeros if + distance = 0xbfff, i.e. H = 1 and the D bits are all 1. + In this case, it is followed by a fourth byte, X. + run length = ((X << 3) | (0 0 0 0 0 L L L)) + 4. + 0 0 1 L L L L L (32..63) Copy of small block within 16kB distance (preferably less than 34B) length = 2 + (L ?: 31 + (zero_bytes * 255) + non_zero_byte)
@@ -165,7 +184,9 @@ Authors ======= This document was written by Willy Tarreau <[email protected]> on 2014/07/19 during an - analysis of the decompression code available in Linux 3.16-rc5. The code is - tricky, it is possible that this document contains mistakes or that a few - corner cases were overlooked. In any case, please report any doubt, fix, or - proposed updates to the author(s) so that the document can be updated. + analysis of the decompression code available in Linux 3.16-rc5, and updated + by Dave Rodgman <[email protected]> on 2018/10/30 to introduce run-length + encoding. The code is tricky, it is possible that this document contains + mistakes or that a few corner cases were overlooked. In any case, please + report any doubt, fix, or proposed updates to the author(s) so that the + document can be updated.
include/linux/lzo.h +1 -1
@@ -18,7 +18,7 @@#define LZO1X_1_MEM_COMPRESS (8192 * sizeof(unsigned short))#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS -#define lzo1x_worst_compress (x) ((x) + ((x) / 16) + 64 + 3) +#define lzo1x_worst_compress (x) ((x) + ((x) / 16) + 64 + 3 + 2)/* This requires 'wrkmem' of size LZO1X_1_MEM_COMPRESS */ int lzo1x_1_compress(const unsigned char *src, size_t src_len,
lib/lzo/lzo1x_compress.c +88 -10
158 lines not on this page · raw message
lib/lzo/lzo1x_decompress_safe.c +52 -23
95 lines not on this page · raw message
lib/lzo/lzodefs.h +11 -1
@@ -13,6 +13,12 @@*/ +/* Version +* 0: original lzo version +* 1: lzo with support for RLE +*/ +#define LZO_VERSION 1 +#define COPY4 (dst, src) \ put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))#if defined(CONFIG_X86_64 ) || defined(CONFIG_ARM64 )
@@ -31,6 +37,7 @@#elif defined(CONFIG_X86_64 ) || defined(CONFIG_ARM64 )#define LZO_USE_CTZ64 1#define LZO_USE_CTZ32 1 +#define LZO_FAST_64BIT_MEMORY_ACCESS #elif defined(CONFIG_X86 ) || defined(CONFIG_PPC )#define LZO_USE_CTZ32 1#elif defined(CONFIG_ARM )
@@ -45,7 +52,7 @@#define M1_MAX_OFFSET 0x0400#define M2_MAX_OFFSET 0x0800#define M3_MAX_OFFSET 0x4000 -#define M4_MAX_OFFSET 0xbfff +#define M4_MAX_OFFSET 0xbffe#define M1_MIN_LEN 2#define M1_MAX_LEN 2
@@ -61,6 +68,9 @@#define M3_MARKER 32#define M4_MARKER 16 +#define MIN_ZERO_RUN_LENGTH 4 +#define MAX_ZERO_RUN_LENGTH (2047 + MIN_ZERO_RUN_LENGTH) +#define lzo_dict_t unsigned short#define D_BITS 13#define D_SIZE (1u << D_BITS)
Signature · 1 line
2.16.4
Re: [PATCH 6/7] lib/lzo: implement run-length encoding
Quoted 5 lines · Dave Rodgman
This modifies the bitstream in a way which is backwards compatible (i.e., we can decompress old bitstreams, but old versions of lzo cannot decompress new bitstreams).
Hmmm... Whoa. Help me understand this:
So a btrfs filesystem, compressed with the new lzo, say I run 4.21, won't be readable at all once I reboot under 4.19?
What about compressed net traffic between servers running different kernel version (one with new lzo, the other one with old lzo)? XFRM can be compressed with lzo, can't it?
-ss
Re: [PATCH 6/7] lib/lzo: implement run-length encoding
Quoted 7 lines · Sergey Senozhatsky
Quoted 5 lines · Dave Rodgman
This modifies the bitstream in a way which is backwards compatible (i.e., we can decompress old bitstreams, but old versions of lzo cannot decompress new bitstreams).
Quoted 8 lines
Hmmm... Whoa. Help me understand this:
So a btrfs filesystem, compressed with the new lzo, say I run 4.21, won't be readable at all once I reboot under 4.19?
What about compressed net traffic between servers running different kernel version (one with new lzo, the other one with old lzo)? XFRM can be compressed with lzo, can't it?
Ah, false alarm. Sorry for the noise!
You create a new lzo version in the next patch.
-ss
PATCH v2 7/7 lib/lzo: separate lzo-rle from lzo
In reply to Dave RodgmanTo prevent any issues with persistent data, separate lzo-rle from lzo so that it is treated as a separate algorithm, and lzo is still available.
Use lzo-rle as the default algorithm for
zram.
--- Documentation/lzo.txt | 12 ++- crypto/Makefile | 2 +- crypto/lzo-rle.c | 175 ++++++++++++++++++++++++++++++++++++++++++ crypto/tcrypt.c | 4 +- drivers/block/zram/zcomp.c | 1 + drivers/block/zram/zram_drv.c | 2 +- include/linux/lzo.h | 4 + lib/lzo/lzo1x_compress.c | 42 +++++++--- lib/lzo/lzodefs.h | 3 +- 9 files changed, 227 insertions(+), 18 deletions(-) create mode 100644 crypto/lzo-rle.c
Documentation/lzo.txt +8 -4
@@ -88,6 +88,10 @@ length encoding. This improves speed for data with many zeros, which is a common case for zram. This modifies the bitstream in a backwards compatible way (v1 can correctly decompress v0 compressed data, but v0 cannot read v1 data). +For maximum compatibility, both versions are available under different names +(lzo and lzo-rle). Differences in the encoding are noted in this document with +e.g.: version 1 only. + Byte sequences ==============
@@ -99,8 +103,8 @@ Byte sequences invalid at this place. 17 : bitstream version. If the first byte is 17, the next byte - gives the bitstream version. If the first byte is not 17, - the bitstream version is 0. + gives the bitstream version (version 1 only). If the first byte + is not 17, the bitstream version is 0. 18..21 : copy 0..3 literals state = (byte - 17) = 0..3 [ copy <state> literals ]
@@ -154,8 +158,8 @@ Byte sequences state = S (copy S literals after this block) End of stream is reached if distance == 16384 - In version 1, this instruction is also used to encode a run of zeros if - distance = 0xbfff, i.e. H = 1 and the D bits are all 1. + In version 1 only, this instruction is also used to encode a run of + zeros if distance = 0xbfff, i.e. H = 1 and the D bits are all 1. In this case, it is followed by a fourth byte, X. run length = ((X << 3) | (0 0 0 0 0 L L L)) + 4.
crypto/Makefile +1 -1
@@ -127,7 +127,7 @@ obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o -obj-$(CONFIG_CRYPTO_LZO) += lzo.o +obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o obj-$(CONFIG_CRYPTO_LZ4) += lz4.o obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o obj-$(CONFIG_CRYPTO_842) += 842.o
crypto/lzo-rle.c new file +175 -0
175 lines not on this page · raw message
crypto/tcrypt.c +2 -2
@@ -76,8 +76,8 @@ static char *check[] = {"cast6" ,"arc4" ,"michael_mic" ,"deflate" ,"crc32c" ,"tea" ,"xtea" ,"khazad" ,"wp512" ,"wp384" ,"wp256" ,"tnepres" ,"xeta" ,"fcrypt" ,"camellia" ,"seed" ,"salsa20" ,"rmd128" ,"rmd160" ,"rmd256" ,"rmd320" , -"lzo" ,"cts" ,"sha3-224" ,"sha3-256" ,"sha3-384" ,"sha3-512" , -"streebog256" ,"streebog512" , +"lzo" ,"lzo-rle" ,"cts" ,"sha3-224" ,"sha3-256" ,"sha3-384" , +"sha3-512" ,"streebog256" ,"streebog512" ,NULL };
drivers/block/zram/zcomp.c +1 -0
@@ -20,6 +20,7 @@static const char *const backends[] = {"lzo" , +"lzo-rle" , #if IS_ENABLED(CONFIG_CRYPTO_LZ4)"lz4" , #endif
drivers/block/zram/zram_drv.c +1 -1
@@ -41,7 +41,7 @@ static DEFINE_IDR(zram_index_idr);static DEFINE_MUTEX (zram_index_mutex);static int zram_major; -static const char *default_compressor ="lzo" ; +static const char *default_compressor ="lzo-rle" ;/* Module params (documentation at end) */ static unsigned int num_devices =1 ;
include/linux/lzo.h +4 -0
@@ -24,6 +24,10 @@int lzo1x_1_compress (const unsigned char *src,size_t src_len,unsigned char *dst,size_t *dst_len,void *wrkmem); +/* This requires 'wrkmem' of size LZO1X_1_MEM_COMPRESS */ +int lzorle1x_1_compress (const unsigned char *src,size_t src_len, +unsigned char *dst,size_t *dst_len,void *wrkmem); +/* safe decompression with overrun testing */ int lzo1x_decompress_safe (const unsigned char *src,size_t src_len,unsigned char *dst,size_t *dst_len);
lib/lzo/lzo1x_compress.c +33 -9
84 lines not on this page · raw message
lib/lzo/lzodefs.h +2 -1
@@ -52,7 +52,8 @@#define M1_MAX_OFFSET 0x0400#define M2_MAX_OFFSET 0x0800#define M3_MAX_OFFSET 0x4000 -#define M4_MAX_OFFSET 0xbffe +#define M4_MAX_OFFSET_V0 0xbfff +#define M4_MAX_OFFSET_V1 0xbffe#define M1_MIN_LEN 2#define M1_MAX_LEN 2
Signature · 1 line
2.16.4
Re: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
Quoted 11 lines · Dave Rodgman
Documentation/lzo.txt | 12 ++- crypto/Makefile | 2 +- crypto/lzo-rle.c | 175 ++++++++++++++++++++++++++++++++++++++++++ crypto/tcrypt.c | 4 +- drivers/block/zram/zcomp.c | 1 + drivers/block/zram/zram_drv.c | 2 +- include/linux/lzo.h | 4 + lib/lzo/lzo1x_compress.c | 42 +++++++--- lib/lzo/lzodefs.h | 3 +- 9 files changed, 227 insertions(+), 18 deletions(-) create mode 100644 crypto/lzo-rle.c
[..]
crypto/lzo-rle.c line 133
Quoted 11 lines
crypto/lzo-rle.c new file +11
-0+static struct crypto_alg alg = { + .cra_name ="lzo-rle" , + .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , + .cra_ctxsize =sizeof (struct lzorle_ctx ), + .cra_module =THIS_MODULE , + .cra_init = lzorle_init, + .cra_exit = lzorle_exit, + .cra_u = { .compress = { + .coa_compress = lzorle_compress, + .coa_decompress = lzorle_decompress } } +};
A nitpick:
indentation for .compress assignment is a bit confusing, maybe.
[..]
Quoted 9 lines
+++
b/drivers/block/zram/zcomp.cdrivers/block/zram/zcomp.c +1
-0@@ -20,6 +20,7 @@static const char *const backends[] = {"lzo" , +"lzo-rle" , #if IS_ENABLED(CONFIG_CRYPTO_LZ4)"lz4" , #endif
[..]
drivers/block/zram/zram_drv.c static DEFINE_IDR(zram_index_idr); · line 44
Quoted 7 lines
+++
b/drivers/block/zram/zram_drv.cdrivers/block/zram/zram_drv.c +1
-1@@ -41,7 +41,7 @@ static DEFINE_IDR(zram_index_idr);static DEFINE_MUTEX (zram_index_mutex);static int zram_major; -static const char *default_compressor ="lzo" ; +static const char *default_compressor ="lzo-rle" ;
OK, so it's not just "separate lzo-rle", it's also "switch zram to a new compression algorithm by default". I'd say that usually I'd expect this to be separate patches.
-ss
Re: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
Quoted 15 lines · Sergey Senozhatsky
Quoted 11 lines · Dave Rodgman
Documentation/lzo.txt | 12 ++- crypto/Makefile | 2 +- crypto/lzo-rle.c | 175 ++++++++++++++++++++++++++++++++++++++++++ crypto/tcrypt.c | 4 +- drivers/block/zram/zcomp.c | 1 + drivers/block/zram/zram_drv.c | 2 +- include/linux/lzo.h | 4 + lib/lzo/lzo1x_compress.c | 42 +++++++--- lib/lzo/lzodefs.h | 3 +- 9 files changed, 227 insertions(+), 18 deletions(-)create mode 100644
crypto/lzo-rle.c[..]
Quoted 14 lines
crypto/lzo-rle.c line 133
Quoted 11 lines
crypto/lzo-rle.c new file +11
-0+static struct crypto_alg alg = { + .cra_name ="lzo-rle" , + .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , + .cra_ctxsize =sizeof (struct lzorle_ctx ), + .cra_module =THIS_MODULE , + .cra_init = lzorle_init, + .cra_exit = lzorle_exit, + .cra_u = { .compress = { + .coa_compress = lzorle_compress, + .coa_decompress = lzorle_decompress } } +};A nitpick:
indentation for .compress assignment is a bit confusing, maybe.
Agreed - I've copied this directly from crypto/lzo.c though, so I retained the same style. Cleanup could be a separate patch.
Quoted 17 lines
[..]
Quoted 9 lines
+++
b/drivers/block/zram/zcomp.cdrivers/block/zram/zcomp.c +1
-0@@ -20,6 +20,7 @@static const char *const backends[] = {"lzo" , +"lzo-rle" , #if IS_ENABLED(CONFIG_CRYPTO_LZ4)"lz4" , #endif[..]
Quoted 4 lines
+++
b/drivers/block/zram/zram_drv.cdrivers/block/zram/zram_drv.c +0
-0@@ -41,7 +41,7 @@ static DEFINE_IDR(zram_index_idr);static DEFINE_MUTEX (zram_index_mutex);
Quoted 7 lines
drivers/block/zram/zram_drv.c static DEFINE_IDR(zram_index_idr); · line 44
Quoted 3 lines
drivers/block/zram/zram_drv.c +1
-1static int zram_major; -static const char *default_compressor ="lzo" ; +static const char *default_compressor ="lzo-rle" ;OK, so it's not just "separate lzo-rle", it's also "switch zram to a new compression algorithm by default". I'd say that usually I'd expect this to be separate patches.
Yes, fair point. akpm has picked this up now though, so probably a bit late to break it out into a separate patch?
Dave
Re: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
Quoted 11 lines · On Thu, 29 Nov 2018 10:21:53 +0000 Dave Rodgman <[email protected]> wrote:
Quoted 10 lines
drivers/block/zram/zram_drv.c static DEFINE_IDR(zram_index_idr); · line 44
Quoted 6 lines
drivers/block/zram/zram_drv.c +1
-1@@ -41,7 +41,7 @@ static DEFINE_IDR(zram_index_idr);static DEFINE_MUTEX (zram_index_mutex);static int zram_major; -static const char *default_compressor ="lzo" ; +static const char *default_compressor ="lzo-rle" ;OK, so it's not just "separate lzo-rle", it's also "switch zram to a new compression algorithm by default". I'd say that usually I'd expect this to be separate patches.
Quoted 2 lines
Yes, fair point. akpm has picked this up now though, so probably a bit late to break it out into a separate patch?
That's fine. akpm is flexible ;) Whatever produces the best overall result in the permanent record, please.
Re: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
In reply to Dave RodgmanQuoted 25 lines · Dave Rodgman
Quoted 17 lines
[..]
Quoted 9 lines
+++
b/drivers/block/zram/zcomp.cdrivers/block/zram/zcomp.c +1
-0@@ -20,6 +20,7 @@static const char *const backends[] = {"lzo" , +"lzo-rle" , #if IS_ENABLED(CONFIG_CRYPTO_LZ4)"lz4" , #endif[..]
Quoted 4 lines
+++
b/drivers/block/zram/zram_drv.cdrivers/block/zram/zram_drv.c +0
-0@@ -41,7 +41,7 @@ static DEFINE_IDR(zram_index_idr);static DEFINE_MUTEX (zram_index_mutex);Quoted 7 lines
drivers/block/zram/zram_drv.c static DEFINE_IDR(zram_index_idr); · line 44
Quoted 3 lines
drivers/block/zram/zram_drv.c +1
-1static int zram_major; -static const char *default_compressor ="lzo" ; +static const char *default_compressor ="lzo-rle" ;OK, so it's not just "separate lzo-rle", it's also "switch zram to a new compression algorithm by default". I'd say that usually I'd expect this to be separate patches.
Quoted 2 lines
Yes, fair point. akpm has picked this up now though, so probably a bit late to break it out into a separate patch?
Andrew accepts patches to patches, and patches to patches to patches, etc. He is very flexible :)
I don't have a very strong opinion. Would probably be better to split it, tho. Let's hear from Minchan.
-ss
Re: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
In reply to Sergey SenozhatskyQuoted 15 lines · Sergey Senozhatsky
On (11/27/18 16:19), Dave Rodgman wrote:>
crypto/lzo-rle.c line 133
Quoted 11 lines
crypto/lzo-rle.c new file +11
-0+static struct crypto_alg alg = { + .cra_name ="lzo-rle" , + .cra_flags =CRYPTO_ALG_TYPE_COMPRESS , + .cra_ctxsize =sizeof (struct lzorle_ctx ), + .cra_module =THIS_MODULE , + .cra_init = lzorle_init, + .cra_exit = lzorle_exit, + .cra_u = { .compress = { + .coa_compress = lzorle_compress, + .coa_decompress = lzorle_decompress } } +};A nitpick:
indentation for .compress assignment is a bit confusing, maybe.
Looking a bit more closely, these structs are formatted fairly inconsistently in the crypto directory. So, lzo-rle is consistent with what lzo does... but various other files do it differently.
I'm happy to submit a whitespace cleanup patch if people would like, and get everything in that directory consistent (i.e. adopt a style similar to the example below)?
static struct scomp_alg scomp = {
.alloc_ctx = lzorle_alloc_ctx,
.free_ctx = lzorle_free_ctx,
.compress = lzorle_scompress,
.decompress = lzorle_sdecompress,
.base = {
.cra_name = "lzo-rle",
.cra_driver_name = "lzo-rle-scomp",
.cra_module = THIS_MODULE,
}
};Dave
Re: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
Quoted 7 lines · Dave Rodgman
Looking a bit more closely, these structs are formatted fairly inconsistently in the crypto directory. So, lzo-rle is consistent with what lzo does... but various other files do it differently.
I'm happy to submit a whitespace cleanup patch if people would like, and get everything in that directory consistent (i.e. adopt a style similar to the example below)?
I'm not in any position to ask you to do this; white-space clean ups are not very popular (it's OK for staging tree; not so much otherwise). So we better ask David and Herbert.
Quoted 11 lines
static struct
scomp_algscomp = {.alloc_ctx = lzorle_alloc_ctx, .free_ctx = lzorle_free_ctx, .compress = lzorle_scompress, .decompress = lzorle_sdecompress, .base = { .cra_name = "lzo-rle", .cra_driver_name = "lzo-rle-scomp", .cra_module = THIS_MODULE, } };
Looks nice.
-ss
Herbert Xu
maintainerRe: [PATCH 7/7] lib/lzo: separate lzo-rle from lzo
Quoted 4 lines · Sergey Senozhatsky
I'm not in any position to ask you to do this; white-space clean ups are not very popular (it's OK for staging tree; not so much otherwise). So we better ask David and Herbert.
I'm fine with white space cleanups.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 25 lines · Dave Rodgman
Quoted 5 lines
Right. The number is data dependent. Not all swapped out pages can be compressed; compressed pages that end up being >=
zs_huge_class_size()are considered incompressible and stored as it.I'd say that on my setups around 50-60% of pages are incompressible.
So, just to give a bit more detail: the test setup was a Samsung Chromebook Pro, cycling through 80 tabs in Chrome. With lzo-rle, only 5% of pages increased in size, and 90% of pages compress to 75% of original size (or better). Mean compression ratio was 41%. Importantly for lzo-rle, there are a lot of low-entropy pages where it can do well:
in total about 20% of the data is zeros forming part of a run of 4 or more bytes.As a quick summary of the impact of these patches on bigger chunks of data, I've compared the performance of four different variants of lzo on two large (~40 MB) files. The numbers show round-trip throughput in MB/s:
Variant | Low-entropy | High-entropy Current lzo | 242 | 157 Arm opts | 290 | 159 RLE | 876 | 151 Arm opts + RLE | 1150 | 181
Quoted 3 lines
So both the Arm optimisations (8,16-byte copy & CTZ patches), and the RLE implementation make a significant contribution to the overall performance uplift.
Cool!
-ss