Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
UPSTREAM: zram: support page writeback
Browse files Browse the repository at this point in the history
There is demand to writeback specific process pages to backing store
instead of all idles pages in the system due to storage wear out concerns
and to launching latency of apps which are most of the time idle but are
critical for resume latency.

This patch extends the writeback knob to support a specific page
writeback.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Minchan Kim <[email protected]>
Reviewed-by: Sergey Senozhatsky <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
(cherry picked from commit 0d8359620d9be9823b6b9b3cf2dbe006cbfec594)

Bug: 181035934
Signed-off-by: Amos Bianchi <[email protected]>
Change-Id: I2c2ef973f66c9d780244d39a1833c4246fb28bc2
Signed-off-by: UtsavBalar1231 <[email protected]>
  • Loading branch information
minchank authored and UtsavBalar1231 committed Aug 2, 2021
1 parent 6a21b11 commit f411740
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Documentation/blockdev/zram.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,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 admin want to write a specific page in zram device to backing device,
they could write a page index into the interface.

echo "page_index=1251" > /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.
Expand Down
21 changes: 17 additions & 4 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,19 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
return 1;
}

#define PAGE_WB_SIG "page_index="

#define PAGE_WRITEBACK 0
#define HUGE_WRITEBACK 1
#define IDLE_WRITEBACK 2


static ssize_t writeback_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
struct zram *zram = dev_to_zram(dev);
unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
unsigned long index;
unsigned long index = 0;
struct bio bio;
struct bio_vec bio_vec;
struct page *page;
Expand All @@ -634,8 +638,17 @@ static ssize_t writeback_store(struct device *dev,
mode = IDLE_WRITEBACK;
else if (sysfs_streq(buf, "huge"))
mode = HUGE_WRITEBACK;
else
return -EINVAL;
else {
if (strncmp(buf, PAGE_WB_SIG, sizeof(PAGE_WB_SIG) - 1))
return -EINVAL;

ret = kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index);
if (ret || index >= nr_pages)
return -EINVAL;

nr_pages = 1;
mode = PAGE_WRITEBACK;
}

down_read(&zram->init_lock);
if (!init_done(zram)) {
Expand All @@ -654,7 +667,7 @@ static ssize_t writeback_store(struct device *dev,
goto release_init_lock;
}

for (index = 0; index < nr_pages; index++) {
while (nr_pages--) {
struct bio_vec bvec;

bvec.bv_page = page;
Expand Down

0 comments on commit f411740

Please sign in to comment.