[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240503091823.3616962-12-senozhatsky@chromium.org>
Date: Fri, 3 May 2024 18:17:36 +0900
From: Sergey Senozhatsky <senozhatsky@...omium.org>
To: Andrew Morton <akpm@...ux-foundation.org>,
Minchan Kim <minchan@...nel.org>
Cc: linux-kernel@...r.kernel.org,
linux-block@...r.kernel.org,
Sergey Senozhatsky <senozhatsky@...omium.org>
Subject: [PATCH 11/14] zram: support compression level comp config
Add support for compression level level=N comp configuration
to comp_algorithm and recomp_algorithm knobs.
Note that zram cannot verify ranges, it's a task of
corresponding backends to make sure that level makes
sense.
Signed-off-by: Sergey Senozhatsky <senozhatsky@...omium.org>
---
drivers/block/zram/zram_drv.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index bd8433363cbe..89a2eb37e26c 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1013,6 +1013,12 @@ static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf)
return 0;
}
+static int comp_config_store(struct zram *zram, u32 prio, s32 level)
+{
+ zram->configs[prio].level = level;
+ return 0;
+}
+
static ssize_t comp_algorithm_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1030,6 +1036,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
struct zram *zram = dev_to_zram(dev);
char *args, *param, *val;
char *alg = NULL;
+ s32 level = ZCOMP_CONFIG_NO_LEVEL;
int ret;
args = skip_spaces(buf);
@@ -1049,12 +1056,21 @@ static ssize_t comp_algorithm_store(struct device *dev,
alg = val;
continue;
}
+
+ if (!strcmp(param, "level")) {
+ ret = kstrtoint(val, 10, &level);
+ if (ret)
+ return ret;
+ continue;
+ }
}
if (!alg)
return -EINVAL;
- ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, alg);
+ ret = comp_config_store(zram, ZRAM_PRIMARY_COMP, level);
+ if (!ret)
+ ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, alg);
return ret ? ret : len;
}
@@ -1087,6 +1103,7 @@ static ssize_t recomp_algorithm_store(struct device *dev,
int prio = ZRAM_SECONDARY_COMP;
char *args, *param, *val;
char *alg = NULL;
+ s32 level = ZCOMP_CONFIG_NO_LEVEL;
int ret;
args = skip_spaces(buf);
@@ -1107,6 +1124,13 @@ static ssize_t recomp_algorithm_store(struct device *dev,
return ret;
continue;
}
+
+ if (!strcmp(param, "level")) {
+ ret = kstrtoint(val, 10, &level);
+ if (ret)
+ return ret;
+ continue;
+ }
}
if (!alg)
@@ -1115,7 +1139,9 @@ static ssize_t recomp_algorithm_store(struct device *dev,
if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS)
return -EINVAL;
- ret = __comp_algorithm_store(zram, prio, alg);
+ ret = comp_config_store(zram, prio, level);
+ if (!ret)
+ ret = __comp_algorithm_store(zram, prio, alg);
return ret ? ret : len;
}
#endif
--
2.45.0.rc1.225.g2a3ae87e7f-goog
Powered by blists - more mailing lists