[PATCH 1/2] zram: add a parameter "node_id" for zram

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a parameter "node_id" to zram to support storing pages on specific
node_id node memory.

Now, zram memory allocation is random, however in some cases, specifying
specific nodes for memory allocation for zram may have good effects. In
addition, when memory tier is supported, demotion can be achieved not
only through page migration,  it is also possible to apply for memory by
specifying zram on low-speed device nodes, such as CXL memory devices,
and compressing pages to these devices through memory reclamation to
achieve similar effects to migration.

Signed-off-by: Ze Zuo <zuoze1@xxxxxxxxxx>
Signed-off-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
---
 drivers/block/zram/zram_drv.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 06673c6ca255..692993e48e93 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -45,6 +45,8 @@ static const char *default_compressor = CONFIG_ZRAM_DEF_COMP;
 
 /* Module params (documentation at end) */
 static unsigned int num_devices = 1;
+
+static int node_id = NUMA_NO_NODE;
 /*
  * Pages that compress to sizes equals or greater than this are stored
  * uncompressed in memory.
@@ -53,6 +55,28 @@ static size_t huge_class_size;
 
 static const struct block_device_operations zram_devops;
 
+static int zram_node_id_store(const char *val,
+		const struct kernel_param *kp)
+{
+	int ret, nid;
+
+	ret = kstrtoint(val, 10, &nid);
+	if (ret)
+		return ret;
+	if (nid != NUMA_NO_NODE && !node_online(nid))
+		return -EINVAL;
+	node_id = nid;
+	return 0;
+}
+
+static const struct kernel_param_ops node_id_param_ops = {
+	.set = zram_node_id_store,
+	.get = param_get_int,
+};
+
+module_param_cb(node_id, &node_id_param_ops, &node_id, 0600);
+MODULE_PARM_DESC(node_id, "The node of pre-created zram devices memory alloc");
+
 static void zram_free_page(struct zram *zram, size_t index);
 static int zram_read_page(struct zram *zram, struct page *page, u32 index,
 			  struct bio *parent);
@@ -1233,7 +1257,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
 	size_t num_pages;
 
 	num_pages = disksize >> PAGE_SHIFT;
-	zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
+	zram->table = vzalloc_node(array_size(num_pages, sizeof(*zram->table)), node_id);
 	if (!zram->table)
 		return false;
 
-- 
2.25.1





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux