@@ -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>
@@ -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;
}
@@ -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);
@@ -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)
@@ -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;
}