linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hui Zhu <zhuhui@xiaomi.com>
To: minchan@kernel.org, ngupta@vflare.org,
	sergey.senozhatsky.work@gmail.com, dan.j.williams@intel.com,
	jthumshirn@suse.de, akpm@linux-foundation.org, zhuhui@xiaomi.com,
	re.emese@gmail.com, andriy.shevchenko@linux.intel.com,
	vishal.l.verma@intel.com, hannes@cmpxchg.org, mhocko@suse.com,
	mgorman@techsingularity.net, vbabka@suse.cz,
	vdavydov.dev@gmail.com, kirill.shutemov@linux.intel.com,
	ying.huang@intel.com, yang.shi@linaro.org,
	dave.hansen@linux.intel.com, willy@linux.intel.com,
	vkuznets@redhat.com, vitalywool@gmail.com, jmarchan@redhat.com,
	lstoakes@gmail.com, geliangtang@163.com, viro@zeniv.linux.org.uk,
	hughd@google.com, riel@redhat.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Cc: teawater@gmail.com
Subject: [RFC 2/2] ZRAM: add sysfs switch swap_cache_not_keep
Date: Fri, 25 Nov 2016 16:25:13 +0800	[thread overview]
Message-ID: <1480062313-7361-3-git-send-email-zhuhui@xiaomi.com> (raw)
In-Reply-To: <1480062313-7361-1-git-send-email-zhuhui@xiaomi.com>

This patch add a sysfs interface swap_cache_not_keep to control the swap
cache rule for a ZRAM disk.
Swap will not keep the swap cache anytime if it set to 1.

Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
---
 drivers/block/zram/zram_drv.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 04365b1..bda9bbf 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -30,6 +30,8 @@
 #include <linux/err.h>
 #include <linux/idr.h>
 #include <linux/sysfs.h>
+#include <linux/swap.h>
+#include <asm/barrier.h>
 
 #include "zram_drv.h"
 
@@ -1158,6 +1160,32 @@ static ssize_t reset_store(struct device *dev,
 	return len;
 }
 
+#ifdef CONFIG_SWAP_CACHE_RULE
+static ssize_t swap_cache_not_keep_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct zram *zram = dev_to_zram(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%d\n",
+			 zram->disk->swap_cache_not_keep);
+}
+
+static ssize_t swap_cache_not_keep_store(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t len)
+{
+	struct zram *zram = dev_to_zram(dev);
+	bool rule;
+
+	if (strtobool(buf, &rule) < 0)
+		return -EINVAL;
+	WRITE_ONCE(zram->disk->swap_cache_not_keep, rule);
+
+	swap_cache_rule_update();
+
+	return len;
+}
+#endif
+
 static int zram_open(struct block_device *bdev, fmode_t mode)
 {
 	int ret = 0;
@@ -1190,6 +1218,9 @@ static int zram_open(struct block_device *bdev, fmode_t mode)
 static DEVICE_ATTR_RW(mem_used_max);
 static DEVICE_ATTR_RW(max_comp_streams);
 static DEVICE_ATTR_RW(comp_algorithm);
+#ifdef CONFIG_SWAP_CACHE_RULE
+static DEVICE_ATTR_RW(swap_cache_not_keep);
+#endif
 
 static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_disksize.attr,
@@ -1213,6 +1244,9 @@ static int zram_open(struct block_device *bdev, fmode_t mode)
 	&dev_attr_io_stat.attr,
 	&dev_attr_mm_stat.attr,
 	&dev_attr_debug_stat.attr,
+#ifdef CONFIG_SWAP_CACHE_RULE
+	&dev_attr_swap_cache_not_keep.attr,
+#endif
 	NULL,
 };
 
-- 
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-11-25  8:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25  8:25 [RFC 0/2] Add interface let ZRAM close swap cache Hui Zhu
2016-11-25  8:25 ` [RFC 1/2] SWAP: add interface to let disk " Hui Zhu
2016-11-25  8:25 ` Hui Zhu [this message]
2016-11-28 14:49 ` [RFC 0/2] Add interface let ZRAM " Michal Hocko

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=1480062313-7361-3-git-send-email-zhuhui@xiaomi.com \
    --to=zhuhui@xiaomi.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=geliangtang@163.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jmarchan@redhat.com \
    --cc=jthumshirn@suse.de \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=re.emese@gmail.com \
    --cc=riel@redhat.com \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=teawater@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=vdavydov.dev@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vishal.l.verma@intel.com \
    --cc=vitalywool@gmail.com \
    --cc=vkuznets@redhat.com \
    --cc=willy@linux.intel.com \
    --cc=yang.shi@linaro.org \
    --cc=ying.huang@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox