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@xxxxxxxxxx> --- 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@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>