Skip to contentSkip to conversation

add compression backend abstraction

PATCH Superseded Sergey Senozhatsky 2 participants 5 messages Jan 30, 2014 – Feb 7, 2014

Subsystems (2)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover add compression backend abstraction

This patchset add abstraction layer (zram_comp) to avoid direct LZO calls and use a common compression backend interface instead. Patchset introduces LZ4 support and new device attribute to switch used compression algorithm.

Sergey Senozhatsky (2):
zram: introduce compressing backend abstraction
zram: use zram_comp compressing backends

 drivers/block/zram/Kconfig     |  20 +++-
 drivers/block/zram/Makefile    |   6 +-
 drivers/block/zram/zcomp_lz4.c |  49 ++++++++++
 drivers/block/zram/zcomp_lz4.h |  18 ++++
 drivers/block/zram/zcomp_lzo.c |  49 ++++++++++
 drivers/block/zram/zcomp_lzo.h |  18 ++++
 drivers/block/zram/zram_comp.c | 204 +++++++++++++++++++++++++++++++++++++++++
 drivers/block/zram/zram_comp.h |  64 +++++++++++++
 drivers/block/zram/zram_drv.c  |  96 ++++++++++++-------
 drivers/block/zram/zram_drv.h  |   8 +-
 10 files changed, 492 insertions(+), 40 deletions(-)
 create mode 100644 drivers/block/zram/zcomp_lz4.c
 create mode 100644 drivers/block/zram/zcomp_lz4.h
 create mode 100644 drivers/block/zram/zcomp_lzo.c
 create mode 100644 drivers/block/zram/zcomp_lzo.h
 create mode 100644 drivers/block/zram/zram_comp.c
 create mode 100644 drivers/block/zram/zram_comp.h
Signature · 1 line
1.9.rc1.183.g614c158
#1 lore raw

PATCH v2 1/2 zram: introduce compressing backend abstraction

ZRAM performs direct LZO compression algorithm calls, making it the one and only option. Introduce struct zram_comp in order to support multiple compression algorithms. struct zram_comp defines the following set of compressing backend operations:
.create
.destroy
.compress
.decompress
.workmem_get
.workmem_put

Schematically zram write() usually contains the following steps:
0) preparation (decompression of partioal IO, etc.)
1) lock buffer_lock mutex (protects meta compress buffers)
2) compress (using meta compress buffers)
3) alloc and map zs_pool object
4) copy compressed data (from meta compress buffers) to new object
5) free previous pool page, assign a new one
6) unlock buffer_lock mutex

As we can see, compressing buffers must remain untouched from 1) to 4), because, otherwise, concurrent write() will overwrite data. At the same time, zram_meta must be aware of a) specific compression algorithm memory requirements and b) necessary locking to protect compression buffers. Besides, zram holds buffer_lock almost through the whole write() function, making parallel compression impossible. To remove requirement
a) new struct zcomp_workmem (workmem is a common term used by lzo, lz4 and zlib) contains buffers required by compression algorithm, while new struct zcomp_wm_policy implements workmem handling and locking by means of get() and put() semantics and removes requirement b) from zram meta. In general, workmem_get() turns caller into exclusive user of workmem and workem_put() makes a particular workmem available.

Each compressing backend may use a default workmem policy or provide custom implementation. Default workmem policy (struct zcomp_wm_policy) has a list of idle workmem buffers (at least 1 workmem), spinlock to protect idle list and wait queue, making it possible to have parallel compressions. Each time zram issues a workmem_get() call, the following set of operations performed:
- spin lock buffer_lock
- if idle list is not empty, remove workmem from idle list, spin unlock and return workmem pointer
- if idle list is empty, current adds itself to wait queue. it will be awaken by workmem_put() caller.

workmem_put():
- spin lock buffer_lock
- add workmem to idle list
- spin unlock, wake up sleeper (if any)

zram_comp file contains array of supported compressing backends, which can be altered according to user selection.

Usage examples. To initialize compressing backend:
comp = zcomp_create(NAME) /* NAME e.g. lzo, lz4 */

which performs NAME lookup in array of supported compressing backends and initialises compressing backend if requested algorithm is supported. Compressing:

	wm = comp->workmem_get(comp)
	comp->compress(...)
	[..] /* copy compressed data */
	comp->workmem_put(comp, wm)

Free compessing backend and all ot its workmem buffers:
zcomp_destroy(comp)

The patch implements LZO and LZ4 backends. At this point zcomp_wm_policy keeps only one workmem in the idle list, support for multi workmem buffers will be introduced later.

---
 drivers/block/zram/zcomp_lz4.c |  49 ++++++++++
 drivers/block/zram/zcomp_lz4.h |  18 ++++
 drivers/block/zram/zcomp_lzo.c |  49 ++++++++++
 drivers/block/zram/zcomp_lzo.h |  18 ++++
 drivers/block/zram/zram_comp.c | 204 +++++++++++++++++++++++++++++++++++++++++
 drivers/block/zram/zram_comp.h |  64 +++++++++++++
 6 files changed, 402 insertions(+)
 create mode 100644 drivers/block/zram/zcomp_lz4.c
 create mode 100644 drivers/block/zram/zcomp_lz4.h
 create mode 100644 drivers/block/zram/zcomp_lzo.c
 create mode 100644 drivers/block/zram/zcomp_lzo.h
 create mode 100644 drivers/block/zram/zram_comp.c
 create mode 100644 drivers/block/zram/zram_comp.h
drivers/block/zram/zcomp_lz4.c new file +49 -0
new file mode 100644
index 0000000..0987e70
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2014 Sergey Senozhatsky.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/lz4.h>
+
+#include "zcomp_lz4.h"
+
+static struct zcomp_workmem *workmem_get(struct zram_comp *comp)
+{
+	struct zcomp_wm_policy *policy = comp->private;
+	return wm_policy_workmem_get(policy);
+}
+
+static void workmem_put(struct zram_comp *comp, struct zcomp_workmem *workmem)
+{
+	struct zcomp_wm_policy *policy = comp->private;
+	return wm_policy_workmem_put(policy, workmem);
+}
+
+int zcomp_lz4_create(struct zram_comp *comp)
+{
+	comp->compress = lz4_compress;
+	comp->decompress = lz4_decompress_unknownoutputsize;
+	comp->workmem_get = workmem_get;
+	comp->workmem_put = workmem_put;
+
+	/* lz4 backend uses default wm policy and calls default policy
+	 * workmem get() and put() functions */
+	comp->private = kzalloc(sizeof(struct zcomp_wm_policy), GFP_KERNEL);
+	if (!comp->private)
+		return -ENOMEM;
+	if (wm_policy_init(comp->private, LZ4_MEM_COMPRESS))
+		return -EINVAL;
+	return 0;
+}
+
+void zcomp_lz4_destroy(struct zram_comp *comp)
+{
+	wm_policy_free(comp->private);
+	kfree(comp->private);
+}
drivers/block/zram/zcomp_lz4.h new file +18 -0
new file mode 100644
index 0000000..7988492
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2014 Sergey Senozhatsky.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ZCOMP_LZ4_H_
+#define _ZCOMP_LZ4_H_
+
+#include "zram_comp.h"
+
+int zcomp_lz4_create(struct zram_comp *comp);
+void zcomp_lz4_destroy(struct zram_comp *comp);
+
+#endif /* _ZCOMP_LZ4_H_ */
drivers/block/zram/zcomp_lzo.c new file +49 -0

49 lines not on this page · raw message

drivers/block/zram/zcomp_lzo.h new file +18 -0
new file mode 100644
index 0000000..18c174e
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2014 Sergey Senozhatsky.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ZCOMP_LZO_H_
+#define _ZCOMP_LZO_H_
+
+#include "zram_comp.h"
+
+int zcomp_lzo_create(struct zram_comp *comp);
+void zcomp_lzo_destroy(struct zram_comp *comp);
+
+#endif /* _ZCOMP_LZO_H_ */
drivers/block/zram/zram_comp.c new file +204 -0

204 lines not on this page · raw message

drivers/block/zram/zram_comp.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.9.rc1.183.g614c158
maintainer
#2 lore raw

Re: [PATCHv2 1/2] zram: introduce compressing backend abstraction

Hello Sergey,

Sorry for late response.

Quoted 11 lines · Sergey Senozhatsky

ZRAM performs direct LZO compression algorithm calls, making it the one and only option. Introduce struct zram_comp in order to support multiple compression algorithms. struct zram_comp defines the following set of compressing backend operations:
.create
.destroy
.compress
.decompress
.workmem_get
.workmem_put

Quoted 6 lines

Schematically zram write() usually contains the following steps:
0) preparation (decompression of partioal IO, etc.)
1) lock buffer_lock mutex (protects meta compress buffers)
2) compress (using meta compress buffers)
3) alloc and map zs_pool object
4) copy compressed data (from meta compress buffers) to new object

object allocated by 3)

Quoted 16 lines

5) free previous pool page, assign a new one
6) unlock buffer_lock mutex

As we can see, compressing buffers must remain untouched from 1) to 4), because, otherwise, concurrent write() will overwrite data. At the same time, zram_meta must be aware of a) specific compression algorithm memory requirements and b) necessary locking to protect compression buffers. Besides, zram holds buffer_lock almost through the whole write() function, making parallel compression impossible. To remove requirement
a) new struct zcomp_workmem (workmem is a common term used by lzo, lz4 and zlib) contains buffers required by compression algorithm, while new struct zcomp_wm_policy implements workmem handling and locking by means of get() and put() semantics and removes requirement b) from zram meta. In general, workmem_get() turns caller into exclusive user of workmem and workem_put() makes a particular workmem available.

Quoted 6 lines

Each compressing backend may use a default workmem policy or provide custom implementation. Default workmem policy (struct zcomp_wm_policy) has a list of idle workmem buffers (at least 1 workmem), spinlock to protect idle list and wait queue, making it possible to have parallel compressions. Each time zram issues a workmem_get() call, the following set of operations performed:

I'm still really not sure why backend should know workmem policy. I think it's matter of upper layer, not backend.
Yeb, surely, you have a reason but it's very hard for me to know it by this patchset so I'd like to divide the patchset.
(You don't need to explain it in here and I expect it would be clear if you separate it like I suggested below).
Pz, see below.

Quoted 10 lines

- spin lock buffer_lock
- if idle list is not empty, remove workmem from idle list, spin unlock and return workmem pointer
- if idle list is empty, current adds itself to wait queue. it will be awaken by workmem_put() caller.

workmem_put():
- spin lock buffer_lock
- add workmem to idle list
- spin unlock, wake up sleeper (if any)

Good.

Quoted 18 lines

zram_comp file contains array of supported compressing backends, which can be altered according to user selection.

Usage examples. To initialize compressing backend:
comp = zcomp_create(NAME) /* NAME e.g. lzo, lz4 */

which performs NAME lookup in array of supported compressing backends and initialises compressing backend if requested algorithm is supported. Compressing:

	wm = comp->workmem_get(comp)
	comp->compress(...)
	[..] /* copy compressed data */
	comp->workmem_put(comp, wm)

Free compessing backend and all ot its workmem buffers:
zcomp_destroy(comp)

Quoted 8 lines

The patch implements LZO and LZ4 backends. At this point zcomp_wm_policy keeps only one workmem in the idle list, support for multi workmem buffers will be introduced later.

---
 drivers/block/zram/zcomp_lz4.c |  49 ++++++++++
 drivers/block/zram/zcomp_lz4.h |  18 ++++

Please don't include lz4 in this patch. It should be separated and description of the patch surely should include the number to prove lz4 is better than lzo in *what* workload so it should make everybody easy to convince.

And let's separate this patchset following as

1. abstract compressor with zram_comp.
2. Support configurable compressor
3. support zcomp multi buffers
4. support lz4

Please don't add workmem policy in patch 1 because we still use only a buffer until 3 so patch 1, 2 would be very simple. Patch 3 might introduce wm policy. Then, it would be very clear why we need it for zomp_multi so that it would make review easy.

If 1,2,3 have no problem and apparenlty lz4 has a benefit, patch 4 will be merged easily but If lz4 were rejected by some reason, we could support another compression easily since patch 1,2,3 is merged.

Thanks.

Signature · 2 lines
Kind regards,
Minchan Kim
maintainer
#3 lore raw

Re: [PATCHv2 1/2] zram: introduce compressing backend abstraction

Quoted 113 lines · Minchan Kim

Hello Sergey,

Sorry for late response.

Quoted 11 lines · Sergey Senozhatsky

ZRAM performs direct LZO compression algorithm calls, making it the one and only option. Introduce struct zram_comp in order to support multiple compression algorithms. struct zram_comp defines the following set of compressing backend operations:
.create
.destroy
.compress
.decompress
.workmem_get
.workmem_put

Quoted 6 lines

Schematically zram write() usually contains the following steps:
0) preparation (decompression of partioal IO, etc.)
1) lock buffer_lock mutex (protects meta compress buffers)
2) compress (using meta compress buffers)
3) alloc and map zs_pool object
4) copy compressed data (from meta compress buffers) to new object

object allocated by 3)

Quoted 16 lines

5) free previous pool page, assign a new one
6) unlock buffer_lock mutex

As we can see, compressing buffers must remain untouched from 1) to 4), because, otherwise, concurrent write() will overwrite data. At the same time, zram_meta must be aware of a) specific compression algorithm memory requirements and b) necessary locking to protect compression buffers. Besides, zram holds buffer_lock almost through the whole write() function, making parallel compression impossible. To remove requirement
a) new struct zcomp_workmem (workmem is a common term used by lzo, lz4 and zlib) contains buffers required by compression algorithm, while new struct zcomp_wm_policy implements workmem handling and locking by means of get() and put() semantics and removes requirement b) from zram meta. In general, workmem_get() turns caller into exclusive user of workmem and workem_put() makes a particular workmem available.

Quoted 6 lines

Each compressing backend may use a default workmem policy or provide custom implementation. Default workmem policy (struct zcomp_wm_policy) has a list of idle workmem buffers (at least 1 workmem), spinlock to protect idle list and wait queue, making it possible to have parallel compressions. Each time zram issues a workmem_get() call, the following set of operations performed:

I'm still really not sure why backend should know workmem policy. I think it's matter of upper layer, not backend.
Yeb, surely, you have a reason but it's very hard for me to know it by this patchset so I'd like to divide the patchset.
(You don't need to explain it in here and I expect it would be clear if you separate it like I suggested below).
Pz, see below.

Quoted 10 lines

- spin lock buffer_lock
- if idle list is not empty, remove workmem from idle list, spin unlock and return workmem pointer
- if idle list is empty, current adds itself to wait queue. it will be awaken by workmem_put() caller.

workmem_put():
- spin lock buffer_lock
- add workmem to idle list
- spin unlock, wake up sleeper (if any)

Good.

Quoted 18 lines

zram_comp file contains array of supported compressing backends, which can be altered according to user selection.

Usage examples. To initialize compressing backend:
comp = zcomp_create(NAME) /* NAME e.g. lzo, lz4 */

which performs NAME lookup in array of supported compressing backends and initialises compressing backend if requested algorithm is supported. Compressing:

	wm = comp->workmem_get(comp)
	comp->compress(...)
	[..] /* copy compressed data */
	comp->workmem_put(comp, wm)

Free compessing backend and all ot its workmem buffers:
zcomp_destroy(comp)

Quoted 8 lines

The patch implements LZO and LZ4 backends. At this point zcomp_wm_policy keeps only one workmem in the idle list, support for multi workmem buffers will be introduced later.

---
 drivers/block/zram/zcomp_lz4.c |  49 ++++++++++
 drivers/block/zram/zcomp_lz4.h |  18 ++++

Please don't include lz4 in this patch. It should be separated and description of the patch surely should include the number to prove lz4 is better than lzo in *what* workload so it should make everybody easy to convince.

And let's separate this patchset following as

1. abstract compressor with zram_comp.
2. Support configurable compressor
3. support zcomp multi buffers
4. support lz4

Please don't add workmem policy in patch 1 because we still use only a buffer until 3 so patch 1, 2 would be very simple. Patch 3 might introduce wm policy. Then, it would be very clear why we need it for zomp_multi so that it would make review easy.

Quoted 4 lines

If 1,2,3 have no problem and apparenlty lz4 has a benefit, patch 4 will be merged easily but If lz4 were rejected by some reason, we could support another compression easily since patch 1,2,3 is merged.

Hello Sergey,

If I don't show my brain to you, I guess we need more iterations to discuss and it's really waste our time so I send prototype patch to show the concept I am thinking.

Surely, It wouldn't work but it's enough to show my concept.

It's really simple.
Backend could just focus comp/decomp with own algorithm buffer. (ie, backend don't need to know compress_buffer and workmem policy because it's caller's matter, not compression backed).

I hope you complete this patch to work well with your SOB/Copyright if you don't object the direction because most of concept and code are from your idea and implementation.

Thanks.

Quoted 1 line

From 7f042055a30eb0ab22377634520a39568a7d16ac Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Tue, 4 Feb 2014 17:27:25 +0900
Subject: [PATCH] introduce zram_comp

---
 drivers/block/zram/Makefile    |  5 ++-
 drivers/block/zram/zcomp_lzo.c | 29 +++++++++++++++
 drivers/block/zram/zram_comp.c | 84 ++++++++++++++++++++++++++++++++++++++++++
 drivers/block/zram/zram_comp.h | 36 ++++++++++++++++++
 drivers/block/zram/zram_drv.c  | 45 ++++++++++------------
 drivers/block/zram/zram_drv.h  |  6 +--
 6 files changed, 175 insertions(+), 30 deletions(-)
 create mode 100644 drivers/block/zram/zcomp_lzo.c
 create mode 100644 drivers/block/zram/zram_comp.c
 create mode 100644 drivers/block/zram/zram_comp.h
drivers/block/zram/Makefile +3 -2
index cb0f9ced6a93..7a4de6cce4e4 100644
@@ -1,3 +1,4 @@
-zram-y	:=	zram_drv.o
+zram-y := zram_drv.o
+zram-y += zcomp_lzo.o zram_comp.o
 
-obj-$(CONFIG_ZRAM)	+=	zram.o
+obj-$(CONFIG_ZRAM) += zram.o
drivers/block/zram/zcomp_lzo.c new file +29 -0
new file mode 100644
index 000000000000..2a58d5392d4d
@@ -0,0 +1,29 @@
+#include "zram_comp.h"
+
+#include <linux/lzo.h>
+
+void *lzo_init(void)
+{
+	void *private = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
+	return private;
+}
+
+void lzo_free(void *private)
+{
+	kfree(private);
+}
+
+int lzo_compress_page(unsigned char *in, size_t in_len,
+			unsigned char *out, size_t *out_len,
+			void *private)
+{
+	return lzo1x_1_compress(in, in_len, out, out_len, private);
+}
+
+const struct zram_comp zcomp_lzo = {
+	.init = lzo_init,
+	.destroy = lzo_free,
+	.compress_page = lzo_compress_page,
+	.decompress_page = lzo1x_decompress_safe,
+	.name = "lzo",
+};
drivers/block/zram/zram_comp.c new file +84 -0

84 lines not on this page · raw message

drivers/block/zram/zram_comp.h new file +36 -0
new file mode 100644
index 000000000000..705b8231f4d5
@@ -0,0 +1,36 @@
+#ifndef __ZRAM_COMP_H_
+#define __ZRAM_COMP_H_
+
+#include <linux/slab.h>
+#include "zram_drv.h"
+
+struct zcomp_strm {
+	void *private;
+	void *compress_buffer;
+	struct list_head list;
+};
+
+struct zram_comp {
+
+	struct list_head strm_list;
+	struct mutex lock;
+	wait_queue_head_t wait;
+
+	int (*compress_page)(unsigned char *in, size_t in_len,
+			unsigned char *out, size_t *out_len, void *private);
+	int (*decompress_page)(const unsigned char *in, size_t in_len,
+			  unsigned char *out, size_t *out_len);
+
+	void *(*init)(void);
+	void (*destroy)(void *private);
+	char name[10];
+};
+
+struct zcomp_strm *zcomp_get_strm(struct zram_comp *comp);
+void zcomp_put_strm(struct zram_comp *comp, struct zcomp_strm *strm);
+int zcomp_compress_page(struct zram_comp *comp, struct zcomp_strm *strm,
+			unsigned char *in, size_t *clen);
+struct zram_comp *zcomp_create(char *comp_name, int nr_strm);
+void zcomp_destroy(struct zram_comp *comp);
+
+#endif
drivers/block/zram/zram_drv.c +20 -25

128 lines not on this page · raw message

drivers/block/zram/zram_drv.h +3 -3
index 1d5b1f5786a8..57d5a63456e7 100644
@@ -18,6 +18,8 @@
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
 #include <linux/zsmalloc.h>
+#include <linux/rwsem.h>
+#include <linux/wait.h>
 
 /*
  * Some arbitrary value. This is just to catch
@@ -81,15 +83,13 @@ struct zram_stats {
 
 struct zram_meta {
 	rwlock_t tb_lock;	/* protect table */
-	void *compress_workmem;
-	void *compress_buffer;
 	struct table *table;
 	struct zs_pool *mem_pool;
-	struct mutex buffer_lock; /* protect compress buffers */
 };
 
 struct zram {
 	struct zram_meta *meta;
+	struct zram_comp *comp;
 	struct request_queue *queue;
 	struct gendisk *disk;
 	/* Prevent concurrent execution of device init, reset and R/W request */
Signature · 5 lines
1.8.5.2

-- 
Kind regards,
Minchan Kim
#4 lore raw

PATCH v2 2/2 zram: use zram_comp compressing backends

In reply to Sergey Senozhatsky

1) Use zram_comp in zram instead of direct LZO calls.

2) Introduce Kconfig ZRAM_LZO_COMPRESS and ZRAM_LZ4_COMPRESS options to enable/disable LZO and LZ4 backends respectively.

3) Add compressor device attr that allows to list and select compression algorithms.

usage example:
List available compression algorithms (currently selected one is LZO):
cat /sys/block/zram0/compressor
<lzo> lz4

Change compression algorithm to LZ4:
echo lz4 > /sys/block/zram0/compressor
cat /sys/block/zram0/compressor
lzo <lz4>

iozone test buffer_lock mutex' vs single workmem and spinlock' (each test was performed on cold, freashly created zram device, ext4 file system, LZO):
./iozone -t -T -R -l 3 -u 3 -r 16K -s 60M -I +Z
test unpatсhed patched
-------------------------------------------------

  Initial write:    341274.03   |   465984.82
        Rewrite:    527752.14   |   587844.27
           Read:   2668083.00   |  3527865.95
        Re-read:   2479428.12   |  3497152.56
   Reverse Read:   1563745.16   |  2463020.33
    Stride read:   1916311.84   |  2675575.14
    Random read:   2099906.09   |  2758833.45
 Mixed workload:   1631288.54   |  2439302.68
   Random write:    428555.50   |   578720.39
         Pwrite:    339857.66   |   415078.43
          Pread:   1523965.55   |  1417191.77
         Fwrite:   1571574.03   |  1447609.02
          Fread:   5449851.44   |  5563909.53

./iozone -t -T -R -l 3 -u 3 -r 16K -s 60M -I +Z
test unpatсhed patched
-------------------------------------------------

  Initial write:    435205.70   |   513995.38
        Rewrite:    617956.68   |   600445.49
           Read:   3379175.66   |  3354820.31
        Re-read:   3344446.66   |  3484581.59
   Reverse Read:   2215915.09   |  2689347.80
    Stride read:   2570020.28   |  2797849.55
    Random read:   2751191.27   |  2830580.06
 Mixed workload:   1647681.38   |  2382402.29
   Random write:    591968.77   |   597967.23
         Pwrite:    441869.31   |   526409.72
          Pread:   1530294.05   |  1466025.38
         Fwrite:   1634969.22   |  1757762.27
          Fread:   4782938.06   |  5643076.25
---
 drivers/block/zram/Kconfig    | 20 ++++++++-
 drivers/block/zram/Makefile   |  6 ++-
 drivers/block/zram/zram_drv.c | 96 ++++++++++++++++++++++++++++---------------
 drivers/block/zram/zram_drv.h |  8 ++--
 4 files changed, 90 insertions(+), 40 deletions(-)
drivers/block/zram/Kconfig +18 -2
index 3450be8..4de410d 100644
@@ -1,8 +1,6 @@
 config ZRAM
 	tristate "Compressed RAM block device support"
 	depends on BLOCK && SYSFS && ZSMALLOC
-	select LZO_COMPRESS
-	select LZO_DECOMPRESS
 	default n
 	help
 	  Creates virtual block devices called /dev/zramX (X = 0, 1, ...).
@@ -15,6 +13,24 @@ config ZRAM
 
 	  See zram.txt for more information.
 
+config ZRAM_LZO_COMPRESS
+	bool "Compressed RAM LZO support"
+	depends on ZRAM
+	select LZO_COMPRESS
+	select LZO_DECOMPRESS
+	default y
+	help
+	  This option adds LZO compression algorithm support.
+
+config ZRAM_LZ4_COMPRESS
+	bool "Compressed RAM LZ4 support"
+	depends on ZRAM
+	select LZ4_COMPRESS
+	select LZ4_DECOMPRESS
+	default n
+	help
+	  This option adds LZ4 compression algorithm support.
+
 config ZRAM_DEBUG
 	bool "Compressed RAM block device debug support"
 	depends on ZRAM
drivers/block/zram/Makefile +5 -1
index cb0f9ce..c649600 100644
@@ -1,3 +1,7 @@
-zram-y	:=	zram_drv.o
+zram-y	:=	zram_comp.o zram_drv.o
+
+zram-$(CONFIG_ZRAM_LZO_COMPRESS) += zcomp_lzo.o
+
+zram-$(CONFIG_ZRAM_LZ4_COMPRESS) += zcomp_lz4.o
 
 obj-$(CONFIG_ZRAM)	+=	zram.o
drivers/block/zram/zram_drv.c +63 -33

234 lines not on this page · raw message

drivers/block/zram/zram_drv.h +4 -4
index 1d5b1f5..a2e17d7 100644
@@ -16,9 +16,10 @@
 #define _ZRAM_DRV_H_
 
 #include <linux/spinlock.h>
-#include <linux/mutex.h>
 #include <linux/zsmalloc.h>
 
+#include "zram_comp.h"
+
 /*
  * Some arbitrary value. This is just to catch
  * invalid value for num_devices module parameter.
@@ -81,17 +82,16 @@ struct zram_stats {
 
 struct zram_meta {
 	rwlock_t tb_lock;	/* protect table */
-	void *compress_workmem;
-	void *compress_buffer;
 	struct table *table;
 	struct zs_pool *mem_pool;
-	struct mutex buffer_lock; /* protect compress buffers */
 };
 
 struct zram {
 	struct zram_meta *meta;
 	struct request_queue *queue;
 	struct gendisk *disk;
+	struct zram_comp *comp;
+
 	/* Prevent concurrent execution of device init, reset and R/W request */
 	struct rw_semaphore init_lock;
 	/*
Signature · 1 line
1.9.rc1.183.g614c158