[RFC PATCH v1 4/5] zram: add fold sysfs knob
From: Alexey Romanov
Date: Tue Apr 18 2023 - 02:25:27 EST
Allow zram to fold identical zsmalloc objects into single one:
echo 1 > /sys/block/zramX/fold
Signed-off-by: Alexey Romanov <avromanov@xxxxxxxxxxxxxx>
---
drivers/block/zram/zram_drv.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e290d6d97047..06a614d1643d 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1184,6 +1184,25 @@ static ssize_t compact_store(struct device *dev,
return len;
}
+#ifdef CONFIG_ZSMALLOC_FOLD
+static ssize_t fold_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ struct zram *zram = dev_to_zram(dev);
+
+ down_read(&zram->init_lock);
+ if (!init_done(zram)) {
+ up_read(&zram->init_lock);
+ return -EINVAL;
+ }
+
+ zs_fold(zram->mem_pool);
+ up_read(&zram->init_lock);
+
+ return len;
+}
+#endif
+
static ssize_t io_stat_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -2313,6 +2332,9 @@ static DEVICE_ATTR_RW(writeback_limit_enable);
static DEVICE_ATTR_RW(recomp_algorithm);
static DEVICE_ATTR_WO(recompress);
#endif
+#ifdef CONFIG_ZSMALLOC_FOLD
+static DEVICE_ATTR_WO(fold);
+#endif
static struct attribute *zram_disk_attrs[] = {
&dev_attr_disksize.attr,
@@ -2339,6 +2361,9 @@ static struct attribute *zram_disk_attrs[] = {
#ifdef CONFIG_ZRAM_MULTI_COMP
&dev_attr_recomp_algorithm.attr,
&dev_attr_recompress.attr,
+#endif
+#ifdef CONFIG_ZSMALLOC_FOLD
+ &dev_attr_fold.attr,
#endif
NULL,
};
--
2.38.1