Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52cf034a authored by Joonsoo Kim's avatar Joonsoo Kim Committed by Gerrit - the friendly Code Review server
Browse files

zram: make deduplication feature optional



Benefit of deduplication is dependent on the workload so it's not
preferable to always enable. Therefore, make it optional in Kconfig
and device param. Default is 'off'. This option will be beneficial
for users who use the zram as blockdev and stores build output to it.

Change-Id: If282bb8aa15c5749859a87cf36db7eb9edb3b1ed
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Signed-off-by: default avatarJoonsoo Kim <iamjoonsoo.kim@lge.com>
Link: https://lore.kernel.org/patchwork/patch/787164/


Patch-mainline: linux-kernel@ Thu, 11 May 2017 22:30:52
Signed-off-by: default avatarCharan Teja Reddy <charante@codeaurora.org>
parent b96fb270
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -98,3 +98,13 @@ Description:
		The backing_dev file is read-write and set up backing
		device for zram to write incompressible pages.
		For using, user should enable CONFIG_ZRAM_WRITEBACK.

What:		/sys/block/zram<id>/use_dedup
Date:		March 2017
Contact:	Joonsoo Kim <iamjoonsoo.kim@lge.com>
Description:
		The use_dedup file is read-write and specifies deduplication
		feature is used or not. If enabled, duplicated data is
		managed by reference count and will not be stored in memory
		twice. Benefit of this feature largely depends on the workload
		so keep attention when use.
+1 −1
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ comp_algorithm RW show and change the compression algorithm
compact           WO    trigger memory compaction
debug_stat        RO    this file is used for zram debugging purposes
backing_dev	  RW	set up backend storage for zram to write out

use_dedup	  RW    show and set deduplication feature

User space is advised to use the following files to read the device statistics.

+14 −0
Original line number Diff line number Diff line
@@ -15,6 +15,20 @@ config ZRAM

	  See zram.txt for more information.

config ZRAM_DEDUP
	bool "Deduplication support for ZRAM data"
	depends on ZRAM
	default n
	help
	  Deduplicate ZRAM data to reduce amount of memory consumption.
	  Advantage largely depends on the workload. In some cases, this
          option reduces memory usage to the half. However, if there is no
	  duplicated data, the amount of memory consumption would be
	  increased due to additional metadata usage. And, there is
	  computation time trade-off. Please check the benefit before
	  enabling this option. Experiment shows the positive effect when
	  the zram is used as blockdev and is used to store build output.

config ZRAM_WRITEBACK
       bool "Write back incompressible page to backing device"
       depends on ZRAM
+2 −1
Original line number Diff line number Diff line
zram-y	:=	zcomp.o zram_drv.o zram_dedup.o
zram-y				:=	zcomp.o zram_drv.o
zram-$(CONFIG_ZRAM_DEDUP)	+=	zram_dedup.o

obj-$(CONFIG_ZRAM)	+=	zram.o
+15 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ void zram_dedup_insert(struct zram *zram, struct zram_entry *new,
	struct rb_node **rb_node, *parent = NULL;
	struct zram_entry *entry;

	if (!zram_dedup_enabled(zram))
		return;

	new->checksum = checksum;
	hash = &zram->hash[checksum % zram->hash_size];
	rb_root = &hash->rb_root;
@@ -148,6 +151,9 @@ struct zram_entry *zram_dedup_find(struct zram *zram, struct page *page,
	void *mem;
	struct zram_entry *entry;

	if (!zram_dedup_enabled(zram))
		return NULL;

	mem = kmap_atomic(page);
	*checksum = zram_dedup_checksum(mem);

@@ -160,6 +166,9 @@ struct zram_entry *zram_dedup_find(struct zram *zram, struct page *page,
void zram_dedup_init_entry(struct zram *zram, struct zram_entry *entry,
				unsigned long handle, unsigned int len)
{
	if (!zram_dedup_enabled(zram))
		return;

	entry->handle = handle;
	entry->refcount = 1;
	entry->len = len;
@@ -167,6 +176,9 @@ void zram_dedup_init_entry(struct zram *zram, struct zram_entry *entry,

bool zram_dedup_put_entry(struct zram *zram, struct zram_entry *entry)
{
	if (!zram_dedup_enabled(zram))
		return true;

	if (zram_dedup_put(zram, entry))
		return false;

@@ -178,6 +190,9 @@ int zram_dedup_init(struct zram *zram, size_t num_pages)
	int i;
	struct zram_hash *hash;

	if (!zram_dedup_enabled(zram))
		return 0;

	zram->hash_size = num_pages >> ZRAM_HASH_SHIFT;
	zram->hash_size = min_t(size_t, ZRAM_HASH_SIZE_MAX, zram->hash_size);
	zram->hash_size = max_t(size_t, ZRAM_HASH_SIZE_MIN, zram->hash_size);
Loading