From: <sthanneeru.opensrc@micron.com>
To: <sthanneeru.opensrc@micron.com>, <linux-cxl@vger.kernel.org>,
<linux-mm@kvack.org>
Cc: <sthanneeru@micron.com>, <aneesh.kumar@linux.ibm.com>,
<dan.j.williams@intel.com>, <ying.huang@intel.com>,
<gregory.price@memverge.com>, <mhocko@suse.com>, <tj@kernel.org>,
<john@jagalactic.com>, <emirakhur@micron.com>,
<vtavarespetr@micron.com>, <Ravis.OpenSrc@micron.com>,
<Jonathan.Cameron@huawei.com>, <linux-kernel@vger.kernel.org>,
Ravi Jonnalagadda <ravis.opensrc@micron.com>
Subject: [PATCH 1/2] base/node: Add sysfs for memtier_override
Date: Wed, 13 Dec 2023 23:23:28 +0530 [thread overview]
Message-ID: <20231213175329.594-2-sthanneeru.opensrc@micron.com> (raw)
In-Reply-To: <20231213175329.594-1-sthanneeru.opensrc@micron.com>
From: Srinivasulu Thanneeru <sthanneeru.opensrc@micron.com>
This patch introduces a new memtier_override sysfs.
memtier_override is the current memory tier of the node.
To migrate, replace it with the id of the desired memory tier.
adistance_offset is the required offset from memtype to move
the node to the target memory tier(i.e, memtier_override).
Signed-off-by: Srinivasulu Thanneeru <sthanneeru.opensrc@micron.com>
Signed-off-by: Ravi Jonnalagadda <ravis.opensrc@micron.com>
---
Documentation/ABI/stable/sysfs-devices-node | 7 ++++
drivers/base/node.c | 41 +++++++++++++++++++++
include/linux/memory-tiers.h | 6 +++
include/linux/node.h | 6 +++
mm/memory-tiers.c | 19 +++++++++-
5 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/stable/sysfs-devices-node b/Documentation/ABI/stable/sysfs-devices-node
index 402af4b2b905..447a599cc536 100644
--- a/Documentation/ABI/stable/sysfs-devices-node
+++ b/Documentation/ABI/stable/sysfs-devices-node
@@ -70,6 +70,13 @@ Description:
Distance between the node and all the other nodes
in the system.
+What: /sys/devices/system/node/nodeX/memtier_overwrite
+Date: December 2023
+Contact: Srinivasulu Thanneeru <sthanneeru.opensrc@micron.com>
+Description:
+ The current memory tier of the node.
+ To migrate, replace it with the id of the desired memory tier.
+
What: /sys/devices/system/node/nodeX/vmstat
Date: October 2002
Contact: Linux Memory Management list <linux-mm@kvack.org>
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 493d533f8375..788176b3585a 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -7,6 +7,7 @@
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/memory.h>
+#include <linux/memory-tiers.h>
#include <linux/vmstat.h>
#include <linux/notifier.h>
#include <linux/node.h>
@@ -569,11 +570,49 @@ static ssize_t node_read_distance(struct device *dev,
}
static DEVICE_ATTR(distance, 0444, node_read_distance, NULL);
+static ssize_t memtier_override_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int nid = dev->id;
+ int len = 0;
+
+ len += sysfs_emit(buf, "memory_tier%d\n", node_devices[nid]->memtier);
+ return len;
+}
+
+static ssize_t memtier_override_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ int nid = dev->id;
+ int ret, memtier;
+
+ ret = kstrtoint(buf, 0, &memtier);
+
+ if (ret)
+ return ret;
+ if (memtier < 0 || memtier > MAX_MEMTIERID)
+ return -EINVAL;
+ if (node_devices[nid]->memtier == memtier)
+ return size;
+ ret = get_memtier_adistance_offset(nid, memtier);
+ node_devices[nid]->adistance_offset = ret;
+
+ return size;
+}
+static DEVICE_ATTR_RW(memtier_override);
+
+void set_node_memtierid(int node, int memtierid)
+{
+ node_devices[node]->memtier = memtierid;
+}
+
static struct attribute *node_dev_attrs[] = {
&dev_attr_meminfo.attr,
&dev_attr_numastat.attr,
&dev_attr_distance.attr,
&dev_attr_vmstat.attr,
+ &dev_attr_memtier_override.attr,
NULL
};
@@ -883,6 +922,8 @@ int __register_one_node(int nid)
INIT_LIST_HEAD(&node_devices[nid]->access_list);
node_init_caches(nid);
+ node_devices[nid]->memtier = 0;
+ node_devices[nid]->adistance_offset = 0;
return error;
}
diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h
index 1e39d27bee41..0dba8027e785 100644
--- a/include/linux/memory-tiers.h
+++ b/include/linux/memory-tiers.h
@@ -20,6 +20,11 @@
*/
#define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1))
+/*
+ * Memory tier id is derived from abstract distance(signed 32bits)
+ */
+#define MAX_MEMTIERID (0xFFFFFFFF >> (MEMTIER_CHUNK_BITS + 1))
+
struct memory_tier;
struct memory_dev_type {
/* list of memory types that are part of same tier as this type */
@@ -48,6 +53,7 @@ int mt_calc_adistance(int node, int *adist);
int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf,
const char *source);
int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist);
+int get_memtier_adistance_offset(int node, int memtier);
#ifdef CONFIG_MIGRATION
int next_demotion_node(int node);
void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
diff --git a/include/linux/node.h b/include/linux/node.h
index 427a5975cf40..1c4f4be39db4 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -83,6 +83,8 @@ static inline void node_set_perf_attrs(unsigned int nid,
struct node {
struct device dev;
struct list_head access_list;
+ int memtier;
+ int adistance_offset;
#ifdef CONFIG_HMEM_REPORTING
struct list_head cache_attrs;
struct device *cache_dev;
@@ -138,6 +140,7 @@ extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
extern int register_memory_node_under_compute_node(unsigned int mem_nid,
unsigned int cpu_nid,
unsigned access);
+extern void set_node_memtierid(int node, int memtierid);
#else
static inline void node_dev_init(void)
{
@@ -165,6 +168,9 @@ static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
{
}
+static inline void set_node_memtierid(int node, int memtierid)
+{
+}
#endif
#define to_node(device) container_of(device, struct node, dev)
diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 8d5291add2bc..31ed3c577836 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -167,6 +167,21 @@ static const struct attribute_group *memtier_dev_groups[] = {
NULL
};
+int get_memtier_adistance_offset(int node, int memtier)
+{
+ struct memory_dev_type *memtype;
+ int adistance_offset;
+
+ memtype = node_memory_types[node].memtype;
+ /*
+ * Calculate the adistance offset required from memtype
+ * to move node to target memory tier.
+ */
+ adistance_offset = (memtier << MEMTIER_CHUNK_BITS) -
+ memtype->adistance;
+ return adistance_offset;
+}
+
static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memtype)
{
int ret;
@@ -497,8 +512,10 @@ static struct memory_tier *set_node_memory_tier(int node)
memtype = node_memory_types[node].memtype;
node_set(node, memtype->nodes);
memtier = find_create_memory_tier(memtype);
- if (!IS_ERR(memtier))
+ if (!IS_ERR(memtier)) {
rcu_assign_pointer(pgdat->memtier, memtier);
+ set_node_memtierid(node, memtier->dev.id);
+ }
return memtier;
}
--
2.25.1
next prev parent reply other threads:[~2023-12-13 17:54 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 17:53 [RFC PATCH v2 0/2] Node migration between memory tiers sthanneeru.opensrc
2023-12-13 17:53 ` sthanneeru.opensrc [this message]
2023-12-13 17:53 ` [PATCH 2/2] memory tier: Support node migration between tiers sthanneeru.opensrc
2023-12-15 5:02 ` [RFC PATCH v2 0/2] Node migration between memory tiers Huang, Ying
2023-12-15 17:42 ` Gregory Price
2023-12-18 5:55 ` Huang, Ying
2024-01-03 5:26 ` [EXT] " Srinivasulu Thanneeru
2024-01-03 6:07 ` Huang, Ying
2024-01-03 7:56 ` Srinivasulu Thanneeru
2024-01-03 8:29 ` Huang, Ying
2024-01-03 8:47 ` Srinivasulu Thanneeru
2024-01-04 6:05 ` Huang, Ying
2024-01-08 17:04 ` Gregory Price
2024-01-09 3:41 ` Huang, Ying
2024-01-09 15:50 ` Jonathan Cameron
2024-01-09 17:59 ` Gregory Price
2024-01-10 0:28 ` [External] " Hao Xiang
2024-01-10 14:18 ` Jonathan Cameron
2024-01-10 19:29 ` Hao Xiang
2024-01-12 7:00 ` Huang, Ying
2024-01-12 8:14 ` Hao Xiang
2024-01-15 1:24 ` Huang, Ying
2024-01-10 5:47 ` Huang, Ying
2024-01-10 14:11 ` Jonathan Cameron
2024-01-10 6:06 ` Huang, Ying
2024-01-09 17:34 ` Gregory Price
2023-12-18 8:56 ` Srinivasulu Thanneeru
2023-12-19 3:57 ` Huang, Ying
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=20231213175329.594-2-sthanneeru.opensrc@micron.com \
--to=sthanneeru.opensrc@micron.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Ravis.OpenSrc@micron.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=dan.j.williams@intel.com \
--cc=emirakhur@micron.com \
--cc=gregory.price@memverge.com \
--cc=john@jagalactic.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=sthanneeru@micron.com \
--cc=tj@kernel.org \
--cc=vtavarespetr@micron.com \
--cc=ying.huang@intel.com \
/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