This makes it possible to create memory tiers using fake numa nodes
generated by numa emulation.
The "numa_emulation.adistance=" kernel cmdline option allows you to set
the abstract distance for each NUMA node.
For example, you can create two fake nodes, each in a different memory
tier by booting with "numa=fake=2 numa_emulation.adistance=576,704".
Here, the abstract distances of node0 and node1 are set to 576 and 706,
respectively.
Each memory tier covers an abstract distance chunk size of 128. Thus,
nodes with abstract distances between 512 and 639 are classified into the
same memory tier, and nodes with abstract distances between 640 and 767
are classified into the next slower memory tier.
The abstract distance of fake nodes not specified in the parameter will
be the default DRAM abstract distance of 576.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
v2:
- fix the explanation about cmdline parameter in the commit log
mm/numa_emulation.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/mm/numa_emulation.c b/mm/numa_emulation.c
index 703c8fa05048..a4266da21344 100644
--- a/mm/numa_emulation.c
+++ b/mm/numa_emulation.c
@@ -6,6 +6,9 @@
#include <linux/errno.h>
#include <linux/topology.h>
#include <linux/memblock.h>
+#include <linux/memory-tiers.h>
+#include <linux/module.h>
+#include <linux/node.h>
#include <linux/numa_memblks.h>
#include <asm/numa.h>
#include <acpi/acpi_numa.h>
@@ -344,6 +347,27 @@ static int __init setup_emu2phys_nid(int *dfl_phys_nid)
return max_emu_nid;
}
+static int adistance[MAX_NUMNODES];
+module_param_array(adistance, int, NULL, 0400);
+MODULE_PARM_DESC(adistance, "Abstract distance values for each NUMA node");
+
+static int emu_calculate_adistance(struct notifier_block *self,
+ unsigned long nid, void *data)
+{
+ if (adistance[nid]) {
+ int *adist = data;
+
+ *adist = adistance[nid];
+ return NOTIFY_STOP;
+ }
+ return NOTIFY_OK;
+}
+
+static struct notifier_block emu_adist_nb = {
+ .notifier_call = emu_calculate_adistance,
+ .priority = INT_MIN,
+};
+
/**
* numa_emulation - Emulate NUMA nodes
* @numa_meminfo: NUMA configuration to massage
@@ -532,6 +556,8 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
}
}
+ register_mt_adistance_algorithm(&emu_adist_nb);
+
/* free the copied physical distance table */
memblock_free(phys_dist, phys_size);
return;
--
2.43.0
On 1/8/2026 3:45 PM, Akinobu Mita wrote:
> This makes it possible to create memory tiers using fake numa nodes
> generated by numa emulation.
>
> The "numa_emulation.adistance=" kernel cmdline option allows you to set
> the abstract distance for each NUMA node.
>
> For example, you can create two fake nodes, each in a different memory
> tier by booting with "numa=fake=2 numa_emulation.adistance=576,704".
> Here, the abstract distances of node0 and node1 are set to 576 and 706,
You mention 704 in the cmdline but then mention 706 in the following text.
Please correct the typo. Btw I am not entirely sure if this example is
required
in the commit text here. The Documentation seems to the right place for
this.
> respectively.
>
> Each memory tier covers an abstract distance chunk size of 128. Thus,
> nodes with abstract distances between 512 and 639 are classified into the
> same memory tier, and nodes with abstract distances between 640 and 767
> are classified into the next slower memory tier.
>
> The abstract distance of fake nodes not specified in the parameter will
> be the default DRAM abstract distance of 576.
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
> v2:
> - fix the explanation about cmdline parameter in the commit log
>
> mm/numa_emulation.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/mm/numa_emulation.c b/mm/numa_emulation.c
> index 703c8fa05048..a4266da21344 100644
> --- a/mm/numa_emulation.c
> +++ b/mm/numa_emulation.c
> @@ -6,6 +6,9 @@
> #include <linux/errno.h>
> #include <linux/topology.h>
> #include <linux/memblock.h>
> +#include <linux/memory-tiers.h>
> +#include <linux/module.h>
> +#include <linux/node.h>
> #include <linux/numa_memblks.h>
> #include <asm/numa.h>
> #include <acpi/acpi_numa.h>
> @@ -344,6 +347,27 @@ static int __init setup_emu2phys_nid(int *dfl_phys_nid)
> return max_emu_nid;
> }
>
> +static int adistance[MAX_NUMNODES];
> +module_param_array(adistance, int, NULL, 0400);
> +MODULE_PARM_DESC(adistance, "Abstract distance values for each NUMA node");
> +
> +static int emu_calculate_adistance(struct notifier_block *self,
> + unsigned long nid, void *data)
> +{
> + if (adistance[nid]) {
> + int *adist = data;
> +
> + *adist = adistance[nid];
> + return NOTIFY_STOP;
> + }
> + return NOTIFY_OK;
> +}
> +
> +static struct notifier_block emu_adist_nb = {
> + .notifier_call = emu_calculate_adistance,
> + .priority = INT_MIN,
> +};
> +
> /**
> * numa_emulation - Emulate NUMA nodes
> * @numa_meminfo: NUMA configuration to massage
> @@ -532,6 +556,8 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
> }
> }
>
> + register_mt_adistance_algorithm(&emu_adist_nb);
> +
> /* free the copied physical distance table */
> memblock_free(phys_dist, phys_size);
> return;
Best Regards
Pratyush
2026年1月9日(金) 13:44 Pratyush Brahma <pratyush.brahma@oss.qualcomm.com>: > > > On 1/8/2026 3:45 PM, Akinobu Mita wrote: > > This makes it possible to create memory tiers using fake numa nodes > > generated by numa emulation. > > > > The "numa_emulation.adistance=" kernel cmdline option allows you to set > > the abstract distance for each NUMA node. > > > > For example, you can create two fake nodes, each in a different memory > > tier by booting with "numa=fake=2 numa_emulation.adistance=576,704". > > Here, the abstract distances of node0 and node1 are set to 576 and 706, > You mention 704 in the cmdline but then mention 706 in the following text. Thanks for pointing that out. It was an obvious typo. > Please correct the typo. Btw I am not entirely sure if this example is > required > in the commit text here. The Documentation seems to the right place for > this. This example is also included in the next 2/3 documentation patch. The same typo exists there, so I'll fix it.
On Thu, 8 Jan 2026 19:15:33 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:
> This makes it possible to create memory tiers using fake numa nodes
> generated by numa emulation.
>
> The "numa_emulation.adistance=" kernel cmdline option allows you to set
> the abstract distance for each NUMA node.
>
> For example, you can create two fake nodes, each in a different memory
> tier by booting with "numa=fake=2 numa_emulation.adistance=576,704".
> Here, the abstract distances of node0 and node1 are set to 576 and 706,
> respectively.
>
> Each memory tier covers an abstract distance chunk size of 128. Thus,
> nodes with abstract distances between 512 and 639 are classified into the
> same memory tier, and nodes with abstract distances between 640 and 767
> are classified into the next slower memory tier.
>
> The abstract distance of fake nodes not specified in the parameter will
> be the default DRAM abstract distance of 576.
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
> v2:
> - fix the explanation about cmdline parameter in the commit log
A couple of comments on includes, with those resolved LGTM.
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
>
> mm/numa_emulation.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/mm/numa_emulation.c b/mm/numa_emulation.c
> index 703c8fa05048..a4266da21344 100644
> --- a/mm/numa_emulation.c
> +++ b/mm/numa_emulation.c
> @@ -6,6 +6,9 @@
> #include <linux/errno.h>
> #include <linux/topology.h>
> #include <linux/memblock.h>
> +#include <linux/memory-tiers.h>
> +#include <linux/module.h>
> +#include <linux/node.h>
I can't immediately spot why the new code needs node.h
Should also include
linux/notifier.h for the notifier_block definition.
> #include <linux/numa_memblks.h>
> #include <asm/numa.h>
> #include <acpi/acpi_numa.h>
> @@ -344,6 +347,27 @@ static int __init setup_emu2phys_nid(int *dfl_phys_nid)
> return max_emu_nid;
> }
>
> +static int adistance[MAX_NUMNODES];
> +module_param_array(adistance, int, NULL, 0400);
> +MODULE_PARM_DESC(adistance, "Abstract distance values for each NUMA node");
> +
> +static int emu_calculate_adistance(struct notifier_block *self,
> + unsigned long nid, void *data)
> +{
> + if (adistance[nid]) {
> + int *adist = data;
> +
> + *adist = adistance[nid];
> + return NOTIFY_STOP;
> + }
> + return NOTIFY_OK;
> +}
> +
> +static struct notifier_block emu_adist_nb = {
> + .notifier_call = emu_calculate_adistance,
> + .priority = INT_MIN,
> +};
> +
> /**
> * numa_emulation - Emulate NUMA nodes
> * @numa_meminfo: NUMA configuration to massage
> @@ -532,6 +556,8 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
> }
> }
>
> + register_mt_adistance_algorithm(&emu_adist_nb);
> +
> /* free the copied physical distance table */
> memblock_free(phys_dist, phys_size);
> return;
2026年1月9日(金) 0:47 Jonathan Cameron <jonathan.cameron@huawei.com>: > > On Thu, 8 Jan 2026 19:15:33 +0900 > Akinobu Mita <akinobu.mita@gmail.com> wrote: > > > This makes it possible to create memory tiers using fake numa nodes > > generated by numa emulation. > > > > The "numa_emulation.adistance=" kernel cmdline option allows you to set > > the abstract distance for each NUMA node. > > > > For example, you can create two fake nodes, each in a different memory > > tier by booting with "numa=fake=2 numa_emulation.adistance=576,704". > > Here, the abstract distances of node0 and node1 are set to 576 and 706, > > respectively. > > > > Each memory tier covers an abstract distance chunk size of 128. Thus, > > nodes with abstract distances between 512 and 639 are classified into the > > same memory tier, and nodes with abstract distances between 640 and 767 > > are classified into the next slower memory tier. > > > > The abstract distance of fake nodes not specified in the parameter will > > be the default DRAM abstract distance of 576. > > > > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> > > --- > > v2: > > - fix the explanation about cmdline parameter in the commit log > A couple of comments on includes, with those resolved LGTM. > Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> > > > > > mm/numa_emulation.c | 26 ++++++++++++++++++++++++++ > > 1 file changed, 26 insertions(+) > > > > diff --git a/mm/numa_emulation.c b/mm/numa_emulation.c > > index 703c8fa05048..a4266da21344 100644 > > --- a/mm/numa_emulation.c > > +++ b/mm/numa_emulation.c > > @@ -6,6 +6,9 @@ > > #include <linux/errno.h> > > #include <linux/topology.h> > > #include <linux/memblock.h> > > +#include <linux/memory-tiers.h> > > +#include <linux/module.h> > > +#include <linux/node.h> > > I can't immediately spot why the new code needs node.h The first version used the access_coordinate struct, but that is no longer used, so including linux/node.h is no longer necessary. > > Should also include > linux/notifier.h for the notifier_block definition. I will fix these includes in the next version.
© 2016 - 2026 Red Hat, Inc.