linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zram: support a page writeback
@ 2020-10-12  7:14 Minchan Kim
  2020-10-16  0:25 ` Sergey Senozhatsky
  0 siblings, 1 reply; 3+ messages in thread
From: Minchan Kim @ 2020-10-12  7:14 UTC (permalink / raw)
  To: Andrew Morton
  Cc: LKML, rajekumar, amosbianchi, joaodias, Minchan Kim, Sergey Senozhatsky

There is a demand to writeback specific pages on process to backing store
instead of all idles pages in the system due to storage wear out concern
and launching latency of apps which are most of time idle but critical
for resume latency.

This patch extend writeback knob to support specific page writeback.

Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 Documentation/admin-guide/blockdev/zram.rst |  5 +++++
 drivers/block/zram/zram_drv.c               | 14 ++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst
index a6fd1f9b5faf..f9ce26759906 100644
--- a/Documentation/admin-guide/blockdev/zram.rst
+++ b/Documentation/admin-guide/blockdev/zram.rst
@@ -334,6 +334,11 @@ IOW, unless there is access request, those pages are still idle pages.
 
 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 the page index into the interface.
+
+	echo 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.
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 9100ac36670a..00c194227d89 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -618,6 +618,7 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
 	return 1;
 }
 
+#define PAGE_WRITEBACK 0
 #define HUGE_WRITEBACK 1
 #define IDLE_WRITEBACK 2
 
@@ -626,7 +627,7 @@ static ssize_t writeback_store(struct device *dev,
 {
 	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;
@@ -638,8 +639,13 @@ static ssize_t writeback_store(struct device *dev,
 		mode = IDLE_WRITEBACK;
 	else if (sysfs_streq(buf, "huge"))
 		mode = HUGE_WRITEBACK;
-	else
-		return -EINVAL;
+	else {
+		ret = kstrtol(buf, 10, &index);
+		if (ret || index >= nr_pages)
+			return -EINVAL;
+		nr_pages = 1;
+		mode = PAGE_WRITEBACK;
+	}
 
 	down_read(&zram->init_lock);
 	if (!init_done(zram)) {
@@ -658,7 +664,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;
-- 
2.28.0.1011.ga647a8990f-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] zram: support a page writeback
  2020-10-12  7:14 [PATCH] zram: support a page writeback Minchan Kim
@ 2020-10-16  0:25 ` Sergey Senozhatsky
  2020-10-16 20:29   ` Minchan Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Sergey Senozhatsky @ 2020-10-16  0:25 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Andrew Morton, LKML, rajekumar, amosbianchi, joaodias,
	Sergey Senozhatsky

On (20/10/12 00:14), Minchan Kim wrote:
>  
>  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 the page index into the interface.
> +
> +	echo 1251 > /sys/block/zramX/writeback
> +

May be we can make it more explicit?

	echo "page_index=123" > /sys/block/zramX/writeback

Just in case of future extensions. E.g. someone might want to
have something like

	echo "idle_nr=123" > /sys/block/zramX/writeback

which would write_back 123 idle pages max.

	-ss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] zram: support a page writeback
  2020-10-16  0:25 ` Sergey Senozhatsky
@ 2020-10-16 20:29   ` Minchan Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Minchan Kim @ 2020-10-16 20:29 UTC (permalink / raw)
  To: Sergey Senozhatsky; +Cc: Andrew Morton, LKML, rajekumar, amosbianchi, joaodias

Hi Sergey,

On Fri, Oct 16, 2020 at 09:25:47AM +0900, Sergey Senozhatsky wrote:
> On (20/10/12 00:14), Minchan Kim wrote:
> >  
> >  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 the page index into the interface.
> > +
> > +	echo 1251 > /sys/block/zramX/writeback
> > +
> 
> May be we can make it more explicit?
> 
> 	echo "page_index=123" > /sys/block/zramX/writeback
> 
> Just in case of future extensions. E.g. someone might want to
> have something like
> 
> 	echo "idle_nr=123" > /sys/block/zramX/writeback
> 
> which would write_back 123 idle pages max.
> 
> 	-ss

Make sense. I will use echo "block_index" since page size could be
changed later(e.g., some pages are 4K, some are THP).
I will revise it at next spin.

Thanks, Sergey!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-16 20:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-12  7:14 [PATCH] zram: support a page writeback Minchan Kim
2020-10-16  0:25 ` Sergey Senozhatsky
2020-10-16 20:29   ` Minchan Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).