All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hui Zhu <zhuhui@xiaomi.com>
To: <minchan@kernel.org>, <ngupta@vflare.org>,
	<sergey.senozhatsky.work@gmail.com>, <hughd@google.com>,
	<rostedt@goodmis.org>, <mingo@redhat.com>, <peterz@infradead.org>,
	<acme@kernel.org>, <alexander.shishkin@linux.intel.com>,
	<akpm@linux-foundation.org>, <mhocko@suse.com>,
	<hannes@cmpxchg.org>, <mgorman@techsingularity.net>,
	<vbabka@suse.cz>, <zhuhui@xiaomi.com>, <redkoi@virtuozzo.com>,
	<luto@kernel.org>, <kirill.shutemov@linux.intel.com>,
	<geliangtang@163.com>, <baiyaowei@cmss.chinamobile.com>,
	<dan.j.williams@intel.com>, <vdavydov@virtuozzo.com>,
	<aarcange@redhat.com>, <dvlasenk@redhat.com>,
	<jmarchan@redhat.com>, <koct9i@gmail.com>, <yang.shi@linaro.org>,
	<dave.hansen@linux.intel.com>, <vkuznets@redhat.com>,
	<vitalywool@gmail.com>, <ross.zwisler@linux.intel.com>,
	<tglx@linutronix.de>, <kwapulinski.piotr@gmail.com>,
	<axboe@fb.com>, <mchristi@redhat.com>, <joe@perches.com>,
	<namit@vmware.com>, <riel@redhat.com>,
	<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Cc: <teawater@gmail.com>
Subject: [RFC 3/4] ZRAM: do not swap the page that compressed size bigger than non_swap
Date: Mon, 22 Aug 2016 16:25:08 +0800	[thread overview]
Message-ID: <1471854309-30414-4-git-send-email-zhuhui@xiaomi.com> (raw)
In-Reply-To: <1471854309-30414-1-git-send-email-zhuhui@xiaomi.com>

New option ZRAM_NON_SWAP add a interface "non_swap" to zram.
User can set a unsigned int value to zram.
If a page that compressed size is bigger than limit, mark it as
non-swap.  Then this page will add to unevictable lru list.

This patch doesn't handle the shmem file pages.

Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
---
 drivers/block/zram/Kconfig    | 11 +++++++++++
 drivers/block/zram/zram_drv.c | 39 +++++++++++++++++++++++++++++++++++++++
 drivers/block/zram/zram_drv.h |  4 ++++
 3 files changed, 54 insertions(+)

diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig
index b8ecba6..525caaa 100644
--- a/drivers/block/zram/Kconfig
+++ b/drivers/block/zram/Kconfig
@@ -13,3 +13,14 @@ config ZRAM
 	  disks and maybe many more.
 
 	  See zram.txt for more information.
+
+config ZRAM_NON_SWAP
+	bool "Enable zram non-swap support"
+	depends on ZRAM
+	select NON_SWAP
+	default n
+	help
+	  This option add a interface "non_swap" to zram.  User can set
+	  a unsigned int value to zram.
+	  If a page that compressed size is bigger than limit, mark it as
+	  non-swap.  Then this page will add to unevictable lru list.
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 04365b1..8f7f1ec 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -714,6 +714,14 @@ compress_again:
 		goto out;
 	}
 
+#ifdef CONFIG_ZRAM_NON_SWAP
+	if (!is_partial_io(bvec) && PageAnon(page) &&
+	    zram->non_swap && clen > zram->non_swap) {
+		ret = 0;
+		SetPageNonSwap(page);
+		goto out;
+	}
+#endif
 	src = zstrm->buffer;
 	if (unlikely(clen > max_zpage_size)) {
 		clen = PAGE_SIZE;
@@ -1180,6 +1188,31 @@ static const struct block_device_operations zram_devops = {
 	.owner = THIS_MODULE
 };
 
+#ifdef CONFIG_ZRAM_NON_SWAP
+static ssize_t non_swap_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct zram *zram = dev_to_zram(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", zram->non_swap);
+}
+
+static ssize_t non_swap_store(struct device *dev,
+			      struct device_attribute *attr, const char *buf,
+			      size_t len)
+{
+	struct zram *zram = dev_to_zram(dev);
+
+	zram->non_swap = (unsigned int)memparse(buf, NULL);
+
+	if (zram->non_swap > max_zpage_size)
+		pr_warn("Nonswap should small than max_zpage_size %zu\n",
+			max_zpage_size);
+
+	return len;
+}
+#endif
+
 static DEVICE_ATTR_WO(compact);
 static DEVICE_ATTR_RW(disksize);
 static DEVICE_ATTR_RO(initstate);
@@ -1190,6 +1223,9 @@ static DEVICE_ATTR_RW(mem_limit);
 static DEVICE_ATTR_RW(mem_used_max);
 static DEVICE_ATTR_RW(max_comp_streams);
 static DEVICE_ATTR_RW(comp_algorithm);
+#ifdef CONFIG_ZRAM_NON_SWAP
+static DEVICE_ATTR_RW(non_swap);
+#endif
 
 static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_disksize.attr,
@@ -1210,6 +1246,9 @@ static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_mem_used_max.attr,
 	&dev_attr_max_comp_streams.attr,
 	&dev_attr_comp_algorithm.attr,
+#ifdef CONFIG_ZRAM_NON_SWAP
+	&dev_attr_non_swap.attr,
+#endif
 	&dev_attr_io_stat.attr,
 	&dev_attr_mm_stat.attr,
 	&dev_attr_debug_stat.attr,
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 74fcf10..bd5f38a 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -119,5 +119,9 @@ struct zram {
 	 * zram is claimed so open request will be failed
 	 */
 	bool claim; /* Protected by bdev->bd_mutex */
+
+#ifdef CONFIG_ZRAM_NON_SWAP
+	unsigned int non_swap;
+#endif
 };
 #endif
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: Hui Zhu <zhuhui@xiaomi.com>
To: minchan@kernel.org, ngupta@vflare.org,
	sergey.senozhatsky.work@gmail.com, hughd@google.com,
	rostedt@goodmis.org, mingo@redhat.com, peterz@infradead.org,
	acme@kernel.org, alexander.shishkin@linux.intel.com,
	akpm@linux-foundation.org, mhocko@suse.com, hannes@cmpxchg.org,
	mgorman@techsingularity.net, vbabka@suse.cz, zhuhui@xiaomi.com,
	redkoi@virtuozzo.com, luto@kernel.org,
	kirill.shutemov@linux.intel.com, geliangtang@163.com,
	baiyaowei@cmss.chinamobile.com, dan.j.williams@intel.com,
	vdavydov@virtuozzo.com, aarcange@redhat.com, dvlasenk@redhat.com,
	jmarchan@redhat.com, koct9i@gmail.com, yang.shi@linaro.org,
	dave.hansen@linux.intel.com, vkuznets@redhat.com,
	vitalywool@gmail.com, ross.zwisler@linux.intel.com,
	tglx@linutronix.de, kwapulinski.piotr@gmail.com, axboe@fb.com,
	mchristi@redhat.com, joe@perches.com, namit@vmware.com,
	riel@redhat.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Cc: teawater@gmail.com
Subject: [RFC 3/4] ZRAM: do not swap the page that compressed size bigger than non_swap
Date: Mon, 22 Aug 2016 16:25:08 +0800	[thread overview]
Message-ID: <1471854309-30414-4-git-send-email-zhuhui@xiaomi.com> (raw)
In-Reply-To: <1471854309-30414-1-git-send-email-zhuhui@xiaomi.com>

New option ZRAM_NON_SWAP add a interface "non_swap" to zram.
User can set a unsigned int value to zram.
If a page that compressed size is bigger than limit, mark it as
non-swap.  Then this page will add to unevictable lru list.

This patch doesn't handle the shmem file pages.

Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
---
 drivers/block/zram/Kconfig    | 11 +++++++++++
 drivers/block/zram/zram_drv.c | 39 +++++++++++++++++++++++++++++++++++++++
 drivers/block/zram/zram_drv.h |  4 ++++
 3 files changed, 54 insertions(+)

diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig
index b8ecba6..525caaa 100644
--- a/drivers/block/zram/Kconfig
+++ b/drivers/block/zram/Kconfig
@@ -13,3 +13,14 @@ config ZRAM
 	  disks and maybe many more.
 
 	  See zram.txt for more information.
+
+config ZRAM_NON_SWAP
+	bool "Enable zram non-swap support"
+	depends on ZRAM
+	select NON_SWAP
+	default n
+	help
+	  This option add a interface "non_swap" to zram.  User can set
+	  a unsigned int value to zram.
+	  If a page that compressed size is bigger than limit, mark it as
+	  non-swap.  Then this page will add to unevictable lru list.
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 04365b1..8f7f1ec 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -714,6 +714,14 @@ compress_again:
 		goto out;
 	}
 
+#ifdef CONFIG_ZRAM_NON_SWAP
+	if (!is_partial_io(bvec) && PageAnon(page) &&
+	    zram->non_swap && clen > zram->non_swap) {
+		ret = 0;
+		SetPageNonSwap(page);
+		goto out;
+	}
+#endif
 	src = zstrm->buffer;
 	if (unlikely(clen > max_zpage_size)) {
 		clen = PAGE_SIZE;
@@ -1180,6 +1188,31 @@ static const struct block_device_operations zram_devops = {
 	.owner = THIS_MODULE
 };
 
+#ifdef CONFIG_ZRAM_NON_SWAP
+static ssize_t non_swap_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct zram *zram = dev_to_zram(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%u\n", zram->non_swap);
+}
+
+static ssize_t non_swap_store(struct device *dev,
+			      struct device_attribute *attr, const char *buf,
+			      size_t len)
+{
+	struct zram *zram = dev_to_zram(dev);
+
+	zram->non_swap = (unsigned int)memparse(buf, NULL);
+
+	if (zram->non_swap > max_zpage_size)
+		pr_warn("Nonswap should small than max_zpage_size %zu\n",
+			max_zpage_size);
+
+	return len;
+}
+#endif
+
 static DEVICE_ATTR_WO(compact);
 static DEVICE_ATTR_RW(disksize);
 static DEVICE_ATTR_RO(initstate);
@@ -1190,6 +1223,9 @@ static DEVICE_ATTR_RW(mem_limit);
 static DEVICE_ATTR_RW(mem_used_max);
 static DEVICE_ATTR_RW(max_comp_streams);
 static DEVICE_ATTR_RW(comp_algorithm);
+#ifdef CONFIG_ZRAM_NON_SWAP
+static DEVICE_ATTR_RW(non_swap);
+#endif
 
 static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_disksize.attr,
@@ -1210,6 +1246,9 @@ static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_mem_used_max.attr,
 	&dev_attr_max_comp_streams.attr,
 	&dev_attr_comp_algorithm.attr,
+#ifdef CONFIG_ZRAM_NON_SWAP
+	&dev_attr_non_swap.attr,
+#endif
 	&dev_attr_io_stat.attr,
 	&dev_attr_mm_stat.attr,
 	&dev_attr_debug_stat.attr,
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 74fcf10..bd5f38a 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -119,5 +119,9 @@ struct zram {
 	 * zram is claimed so open request will be failed
 	 */
 	bool claim; /* Protected by bdev->bd_mutex */
+
+#ifdef CONFIG_ZRAM_NON_SWAP
+	unsigned int non_swap;
+#endif
 };
 #endif
-- 
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2016-08-22  8:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-22  8:25 [RFC 0/4] ZRAM: make it just store the high compression rate page Hui Zhu
2016-08-22  8:25 ` Hui Zhu
2016-08-22  8:25 ` [RFC 1/4] vmscan.c: shrink_page_list: unmap anon pages after pageout Hui Zhu
2016-08-22  8:25   ` Hui Zhu
2016-08-22  8:25 ` [RFC 2/4] Add non-swap page flag to mark a page will not swap Hui Zhu
2016-08-22  8:25   ` Hui Zhu
2016-09-06 15:35   ` Steven Rostedt
2016-09-06 15:35     ` Steven Rostedt
2016-08-22  8:25 ` Hui Zhu [this message]
2016-08-22  8:25   ` [RFC 3/4] ZRAM: do not swap the page that compressed size bigger than non_swap Hui Zhu
2016-08-22  8:25 ` [RFC 4/4] vmscan.c: zram: add non swap support for shmem file pages Hui Zhu
2016-08-22  8:25   ` Hui Zhu
2016-08-24  1:04 ` [RFC 0/4] ZRAM: make it just store the high compression rate page Minchan Kim
2016-08-24  1:04   ` Minchan Kim
2016-08-24  1:29   ` Hui Zhu
2016-08-24  1:29     ` Hui Zhu
2016-08-25  6:09 ` Sergey Senozhatsky
2016-08-25  6:09   ` Sergey Senozhatsky
2016-08-25  8:25   ` Hui Zhu
2016-08-25  8:25     ` Hui Zhu
2016-09-05  2:18     ` Minchan Kim
2016-09-05  2:18       ` Minchan Kim
2016-09-05  3:59       ` Sergey Senozhatsky
2016-09-05  3:59         ` Sergey Senozhatsky
2016-09-05  5:12       ` Hui Zhu
2016-09-05  5:12         ` Hui Zhu
2016-09-05  5:51         ` Minchan Kim
2016-09-05  5:51           ` Minchan Kim
2016-09-05  6:02           ` Hui Zhu
2016-09-05  6:02             ` Hui Zhu
2016-09-05  2:12 ` Minchan Kim
2016-09-05  2:12   ` Minchan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471854309-30414-4-git-send-email-zhuhui@xiaomi.com \
    --to=zhuhui@xiaomi.com \
    --cc=aarcange@redhat.com \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=axboe@fb.com \
    --cc=baiyaowei@cmss.chinamobile.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dvlasenk@redhat.com \
    --cc=geliangtang@163.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jmarchan@redhat.com \
    --cc=joe@perches.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=koct9i@gmail.com \
    --cc=kwapulinski.piotr@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mchristi@redhat.com \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namit@vmware.com \
    --cc=ngupta@vflare.org \
    --cc=peterz@infradead.org \
    --cc=redkoi@virtuozzo.com \
    --cc=riel@redhat.com \
    --cc=ross.zwisler@linux.intel.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=teawater@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=vdavydov@virtuozzo.com \
    --cc=vitalywool@gmail.com \
    --cc=vkuznets@redhat.com \
    --cc=yang.shi@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.