lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 25 Nov 2016 16:25:13 +0800
From:   Hui Zhu <zhuhui@...omi.com>
To:     <minchan@...nel.org>, <ngupta@...are.org>,
        <sergey.senozhatsky.work@...il.com>, <dan.j.williams@...el.com>,
        <jthumshirn@...e.de>, <akpm@...ux-foundation.org>,
        <zhuhui@...omi.com>, <re.emese@...il.com>,
        <andriy.shevchenko@...ux.intel.com>, <vishal.l.verma@...el.com>,
        <hannes@...xchg.org>, <mhocko@...e.com>,
        <mgorman@...hsingularity.net>, <vbabka@...e.cz>,
        <vdavydov.dev@...il.com>, <kirill.shutemov@...ux.intel.com>,
        <ying.huang@...el.com>, <yang.shi@...aro.org>,
        <dave.hansen@...ux.intel.com>, <willy@...ux.intel.com>,
        <vkuznets@...hat.com>, <vitalywool@...il.com>,
        <jmarchan@...hat.com>, <lstoakes@...il.com>, <geliangtang@....com>,
        <viro@...iv.linux.org.uk>, <hughd@...gle.com>, <riel@...hat.com>,
        <linux-kernel@...r.kernel.org>, <linux-mm@...ck.org>
CC:     <teawater@...il.com>
Subject: [RFC 2/2] ZRAM: add sysfs switch swap_cache_not_keep

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@...omi.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ