diff options
author | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> | 2014-04-07 18:38:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-07 19:36:01 -0400 |
commit | 6e76668e415adf799839f0ab205142ad7002d260 (patch) | |
tree | 28daf444a4b268352a5c18b333a1204576a2ed9f /drivers/block/zram | |
parent | e46b8a030d76d3c94156c545c3f4c3676d813435 (diff) |
zram: add lz4 algorithm backend
Introduce LZ4 compression backend and make it available for selection.
LZ4 support is optional and requires user to set ZRAM_LZ4_COMPRESS config
option. The default compression backend is LZO.
TEST
(x86_64, core i5, 2 cores + 2 hyperthreading, zram disk size 1G,
ext4 file system, 3 compression streams)
iozone -t 3 -R -r 16K -s 60M -I +Z
Test LZO LZ4
----------------------------------------------
Initial write 1642744.62 1317005.09
Rewrite 2498980.88 1800645.16
Read 3957026.38 5877043.75
Re-read 3950997.38 5861847.00
Reverse Read 2937114.56 5047384.00
Stride read 2948163.19 4929587.38
Random read 3292692.69 4880793.62
Mixed workload 1545602.62 3502940.38
Random write 2448039.75 1758786.25
Pwrite 1670051.03 1338329.69
Pread 2530682.00 5097177.62
Fwrite 3232085.62 3275942.56
Fread 6306880.25 6645271.12
So on my system LZ4 is slower in write-only tests, while it performs
better in read-only and mixed (reads + writes) tests.
Official LZ4 benchmarks available here http://code.google.com/p/lz4/
(linux kernel uses revision r90).
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram')
-rw-r--r-- | drivers/block/zram/Kconfig | 10 | ||||
-rw-r--r-- | drivers/block/zram/Makefile | 2 | ||||
-rw-r--r-- | drivers/block/zram/zcomp.c | 6 | ||||
-rw-r--r-- | drivers/block/zram/zcomp_lz4.c | 47 | ||||
-rw-r--r-- | drivers/block/zram/zcomp_lz4.h | 17 |
5 files changed, 82 insertions, 0 deletions
diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 3450be850399..6489c0fd0ea6 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig | |||
@@ -15,6 +15,16 @@ config ZRAM | |||
15 | 15 | ||
16 | See zram.txt for more information. | 16 | See zram.txt for more information. |
17 | 17 | ||
18 | config ZRAM_LZ4_COMPRESS | ||
19 | bool "Enable LZ4 algorithm support" | ||
20 | depends on ZRAM | ||
21 | select LZ4_COMPRESS | ||
22 | select LZ4_DECOMPRESS | ||
23 | default n | ||
24 | help | ||
25 | This option enables LZ4 compression algorithm support. Compression | ||
26 | algorithm can be changed using `comp_algorithm' device attribute. | ||
27 | |||
18 | config ZRAM_DEBUG | 28 | config ZRAM_DEBUG |
19 | bool "Compressed RAM block device debug support" | 29 | bool "Compressed RAM block device debug support" |
20 | depends on ZRAM | 30 | depends on ZRAM |
diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile index 757c6a5cadff..be0763ff57a2 100644 --- a/drivers/block/zram/Makefile +++ b/drivers/block/zram/Makefile | |||
@@ -1,3 +1,5 @@ | |||
1 | zram-y := zcomp_lzo.o zcomp.o zram_drv.o | 1 | zram-y := zcomp_lzo.o zcomp.o zram_drv.o |
2 | 2 | ||
3 | zram-$(CONFIG_ZRAM_LZ4_COMPRESS) += zcomp_lz4.o | ||
4 | |||
3 | obj-$(CONFIG_ZRAM) += zram.o | 5 | obj-$(CONFIG_ZRAM) += zram.o |
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index aad533a8bc55..d5919031ca8b 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c | |||
@@ -15,6 +15,9 @@ | |||
15 | 15 | ||
16 | #include "zcomp.h" | 16 | #include "zcomp.h" |
17 | #include "zcomp_lzo.h" | 17 | #include "zcomp_lzo.h" |
18 | #ifdef CONFIG_ZRAM_LZ4_COMPRESS | ||
19 | #include "zcomp_lz4.h" | ||
20 | #endif | ||
18 | 21 | ||
19 | /* | 22 | /* |
20 | * single zcomp_strm backend | 23 | * single zcomp_strm backend |
@@ -41,6 +44,9 @@ struct zcomp_strm_multi { | |||
41 | 44 | ||
42 | static struct zcomp_backend *backends[] = { | 45 | static struct zcomp_backend *backends[] = { |
43 | &zcomp_lzo, | 46 | &zcomp_lzo, |
47 | #ifdef CONFIG_ZRAM_LZ4_COMPRESS | ||
48 | &zcomp_lz4, | ||
49 | #endif | ||
44 | NULL | 50 | NULL |
45 | }; | 51 | }; |
46 | 52 | ||
diff --git a/drivers/block/zram/zcomp_lz4.c b/drivers/block/zram/zcomp_lz4.c new file mode 100644 index 000000000000..f2afb7e988c3 --- /dev/null +++ b/drivers/block/zram/zcomp_lz4.c | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Sergey Senozhatsky. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/lz4.h> | ||
13 | |||
14 | #include "zcomp_lz4.h" | ||
15 | |||
16 | static void *zcomp_lz4_create(void) | ||
17 | { | ||
18 | return kzalloc(LZ4_MEM_COMPRESS, GFP_KERNEL); | ||
19 | } | ||
20 | |||
21 | static void zcomp_lz4_destroy(void *private) | ||
22 | { | ||
23 | kfree(private); | ||
24 | } | ||
25 | |||
26 | static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst, | ||
27 | size_t *dst_len, void *private) | ||
28 | { | ||
29 | /* return : Success if return 0 */ | ||
30 | return lz4_compress(src, PAGE_SIZE, dst, dst_len, private); | ||
31 | } | ||
32 | |||
33 | static int zcomp_lz4_decompress(const unsigned char *src, size_t src_len, | ||
34 | unsigned char *dst) | ||
35 | { | ||
36 | size_t dst_len = PAGE_SIZE; | ||
37 | /* return : Success if return 0 */ | ||
38 | return lz4_decompress_unknownoutputsize(src, src_len, dst, &dst_len); | ||
39 | } | ||
40 | |||
41 | struct zcomp_backend zcomp_lz4 = { | ||
42 | .compress = zcomp_lz4_compress, | ||
43 | .decompress = zcomp_lz4_decompress, | ||
44 | .create = zcomp_lz4_create, | ||
45 | .destroy = zcomp_lz4_destroy, | ||
46 | .name = "lz4", | ||
47 | }; | ||
diff --git a/drivers/block/zram/zcomp_lz4.h b/drivers/block/zram/zcomp_lz4.h new file mode 100644 index 000000000000..60613fb29dd8 --- /dev/null +++ b/drivers/block/zram/zcomp_lz4.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Sergey Senozhatsky. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #ifndef _ZCOMP_LZ4_H_ | ||
11 | #define _ZCOMP_LZ4_H_ | ||
12 | |||
13 | #include "zcomp.h" | ||
14 | |||
15 | extern struct zcomp_backend zcomp_lz4; | ||
16 | |||
17 | #endif /* _ZCOMP_LZ4_H_ */ | ||