From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: [PATCH 3/6] zram: add pool_page_order device attribute
Date: Tue, 25 Oct 2022 01:12:10 +0900 [thread overview]
Message-ID: <20221024161213.3221725-4-senozhatsky@chromium.org> (raw)
In-Reply-To: <20221024161213.3221725-1-senozhatsky@chromium.org>
Add a new sysfs knob that allows user-space to set
zsmalloc page order value on per-device basis.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 43 ++++++++++++++++++++++++++++++++++-
drivers/block/zram/zram_drv.h | 2 ++
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e3ef542f9618..517dae4ff21c 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1186,6 +1186,44 @@ static ssize_t mm_stat_show(struct device *dev,
return ret;
}
+static ssize_t pool_page_order_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ u32 val;
+ struct zram *zram = dev_to_zram(dev);
+
+ down_read(&zram->init_lock);
+ val = zram->pool_page_order;
+ up_read(&zram->init_lock);
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+
+static ssize_t pool_page_order_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct zram *zram = dev_to_zram(dev);
+ u32 val;
+
+ if (kstrtou32(buf, 10, &val))
+ return -EINVAL;
+
+ if (val < ZS_MIN_PAGE_ORDER || val > ZS_MAX_PAGE_ORDER)
+ return -EINVAL;
+
+ down_read(&zram->init_lock);
+ if (init_done(zram)) {
+ up_read(&zram->init_lock);
+ return -EINVAL;
+ }
+
+ zram->pool_page_order = val;
+ up_read(&zram->init_lock);
+
+ return len;
+}
+
#ifdef CONFIG_ZRAM_WRITEBACK
#define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12)))
static ssize_t bd_stat_show(struct device *dev,
@@ -1254,7 +1292,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
return false;
zram->mem_pool = zs_create_pool(zram->disk->disk_name,
- ZS_DEFAULT_PAGE_ORDER);
+ zram->pool_page_order);
if (!zram->mem_pool) {
vfree(zram->table);
return false;
@@ -2176,6 +2214,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable);
static DEVICE_ATTR_RW(recomp_algorithm);
static DEVICE_ATTR_WO(recompress);
#endif
+static DEVICE_ATTR_RW(pool_page_order);
static struct attribute *zram_disk_attrs[] = {
&dev_attr_disksize.attr,
@@ -2203,6 +2242,7 @@ static struct attribute *zram_disk_attrs[] = {
&dev_attr_recomp_algorithm.attr,
&dev_attr_recompress.attr,
#endif
+ &dev_attr_pool_page_order.attr,
NULL,
};
@@ -2240,6 +2280,7 @@ static int zram_add(void)
goto out_free_idr;
}
+ zram->pool_page_order = ZS_DEFAULT_PAGE_ORDER;
zram->disk->major = zram_major;
zram->disk->first_minor = device_id;
zram->disk->minors = 1;
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 09b9ceb5dfa3..076d5b17a954 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -120,6 +120,8 @@ struct zram {
*/
u64 disksize; /* bytes */
const char *comp_algs[ZRAM_MAX_ZCOMPS];
+
+ u32 pool_page_order;
/*
* zram is claimed so open request will be failed
*/
--
2.38.0.135.g90850a2211-goog
next prev parent reply other threads:[~2022-10-24 16:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 16:12 [PATCH 0/6] zsmalloc/zram: configurable zspage size Sergey Senozhatsky
2022-10-24 16:12 ` [PATCH 1/6] zsmalloc: turn zspage order into runtime variable Sergey Senozhatsky
2022-10-24 16:12 ` [PATCH 2/6] zsmalloc/zram: pass zspage order to zs_create_pool() Sergey Senozhatsky
2022-10-24 16:12 ` Sergey Senozhatsky [this message]
2022-10-24 16:12 ` [PATCH 4/6] Documentation: document zram pool_page_order attribute Sergey Senozhatsky
2022-10-24 16:12 ` [PATCH 5/6] zsmalloc: break out of loop when found perfect zspage order Sergey Senozhatsky
2022-10-24 16:12 ` [PATCH 6/6] zsmalloc: make sure we select best zspage size Sergey Senozhatsky
2022-10-25 3:26 ` [PATCH 0/6] zsmalloc/zram: configurable " Bagas Sanjaya
2022-10-25 3:42 ` Sergey Senozhatsky
2022-10-25 8:40 ` Bagas Sanjaya
2022-10-25 4:30 ` Sergey Senozhatsky
2022-10-25 7:57 ` Sergey Senozhatsky
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=20221024161213.3221725-4-senozhatsky@chromium.org \
--to=senozhatsky@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
/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