Commit 1067c440 authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Jinjiang Tu
Browse files

zram: add incompressible writeback

mainline inclusion
from mainline-v6.2-rc1
commit b46f9ea3
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I7TWVA
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b46f9ea3cb351587b2cfc68f7211f7a7cc5b6673

-------------------------------------------

Add support for incompressible pages writeback:

  echo incompressible > /sys/block/zramX/writeback

Link: https://lkml.kernel.org/r/20221109115047.2921851-13-senozhatsky@chromium.org


Signed-off-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: Alexey Romanov <avromanov@sberdevices.ru>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Suleiman Souhlal <suleiman@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>

Conflicts:
	Documentation/admin-guide/blockdev/zram.rst
	drivers/block/zram/zram_drv.c

Signed-off-by: default avatarJinjiang Tu <tujinjiang@huawei.com>
parent bfad37fc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -334,6 +334,11 @@ Admin can request writeback of those idle pages at right timing via::

With the command, zram writeback idle pages from memory to the storage.

If a user chooses to writeback only incompressible pages (pages that none of
algorithms can compress) this can be accomplished with::

	echo incompressible > /sys/block/zramX/writeback

If there are lots of write IO with flash device, potentially, it has
flash wearout problem so that admin needs to design write limitation
to guarantee storage health for entire product life.
+11 −4
Original line number Diff line number Diff line
@@ -639,8 +639,9 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
	return 1;
}

#define HUGE_WRITEBACK 1
#define IDLE_WRITEBACK 2
#define HUGE_WRITEBACK			(1<<0)
#define IDLE_WRITEBACK			(1<<1)
#define INCOMPRESSIBLE_WRITEBACK	(1<<2)

static ssize_t writeback_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t len)
@@ -659,6 +660,8 @@ static ssize_t writeback_store(struct device *dev,
		mode = IDLE_WRITEBACK;
	else if (sysfs_streq(buf, "huge"))
		mode = HUGE_WRITEBACK;
	else if (sysfs_streq(buf, "incompressible"))
		mode = INCOMPRESSIBLE_WRITEBACK;
	else
		return -EINVAL;

@@ -717,6 +720,10 @@ static ssize_t writeback_store(struct device *dev,
		if (mode == HUGE_WRITEBACK &&
			!zram_test_flag(zram, index, ZRAM_HUGE))
			goto next;
		if (mode & INCOMPRESSIBLE_WRITEBACK &&
		    !zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE))
			goto next;

		/*
		 * Clearing ZRAM_UNDER_WB is duty of caller.
		 * IOW, zram_free_page never clear it.