Skip to content

Commit 0d83596

Browse files
minchanktorvalds
authored andcommitted
zram: support page writeback
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]>
1 parent 95c9ae1 commit 0d83596

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Documentation/admin-guide/blockdev/zram.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ Admin can request writeback of those idle pages at right timing via::
334334

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

337+
If admin want to write a specific page in zram device to backing device,
338+
they could write a page index into the interface.
339+
340+
echo "page_index=1251" > /sys/block/zramX/writeback
341+
337342
If there are lots of write IO with flash device, potentially, it has
338343
flash wearout problem so that admin needs to design write limitation
339344
to guarantee storage health for entire product life.

drivers/block/zram/zram_drv.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,19 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
620620
return 1;
621621
}
622622

623+
#define PAGE_WB_SIG "page_index="
624+
625+
#define PAGE_WRITEBACK 0
623626
#define HUGE_WRITEBACK 1
624627
#define IDLE_WRITEBACK 2
625628

629+
626630
static ssize_t writeback_store(struct device *dev,
627631
struct device_attribute *attr, const char *buf, size_t len)
628632
{
629633
struct zram *zram = dev_to_zram(dev);
630634
unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
631-
unsigned long index;
635+
unsigned long index = 0;
632636
struct bio bio;
633637
struct bio_vec bio_vec;
634638
struct page *page;
@@ -640,8 +644,17 @@ static ssize_t writeback_store(struct device *dev,
640644
mode = IDLE_WRITEBACK;
641645
else if (sysfs_streq(buf, "huge"))
642646
mode = HUGE_WRITEBACK;
643-
else
644-
return -EINVAL;
647+
else {
648+
if (strncmp(buf, PAGE_WB_SIG, sizeof(PAGE_WB_SIG) - 1))
649+
return -EINVAL;
650+
651+
ret = kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index);
652+
if (ret || index >= nr_pages)
653+
return -EINVAL;
654+
655+
nr_pages = 1;
656+
mode = PAGE_WRITEBACK;
657+
}
645658

646659
down_read(&zram->init_lock);
647660
if (!init_done(zram)) {
@@ -660,7 +673,7 @@ static ssize_t writeback_store(struct device *dev,
660673
goto release_init_lock;
661674
}
662675

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

666679
bvec.bv_page = page;

0 commit comments

Comments
 (0)