Skip to content

Commit 0a8c4aa

Browse files
yhuang-intelakpm00
authored andcommitted
memory tiering: add abstract distance calculation algorithms management
Patch series "memory tiering: calculate abstract distance based on ACPI HMAT". We have the explicit memory tiers framework to manage systems with multiple types of memory, e.g., DRAM in DIMM slots and CXL memory devices. Where, same kind of memory devices will be grouped into memory types, then put into memory tiers. To describe the performance of a memory type, abstract distance is defined. Which is in direct proportion to the memory latency and inversely proportional to the memory bandwidth. To keep the code as simple as possible, fixed abstract distance is used in dax/kmem to describe slow memory such as Optane DCPMM. To support more memory types, in this series, we added the abstract distance calculation algorithm management mechanism, provided a algorithm implementation based on ACPI HMAT, and used the general abstract distance calculation interface in dax/kmem driver. So, dax/kmem can support HBM (high bandwidth memory) in addition to the original Optane DCPMM. This patch (of 4): The abstract distance may be calculated by various drivers, such as ACPI HMAT, CXL CDAT, etc. While it may be used by various code which hot-add memory node, such as dax/kmem etc. To decouple the algorithm users and the providers, the abstract distance calculation algorithms management mechanism is implemented in this patch. It provides interface for the providers to register the implementation, and interface for the users. Multiple algorithm implementations can cooperate via calculating abstract distance for different memory nodes. The preference of algorithm implementations can be specified via priority (notifier_block.priority). Link: https://lkml.kernel.org/r/20230721012932.190742-1-ying.huang@intel.com Link: https://lkml.kernel.org/r/20230721012932.190742-2-ying.huang@intel.com Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Wei Xu <weixugc@google.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Yang Shi <shy828301@gmail.com> Cc: Rafael J Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent a79b3be commit 0a8c4aa

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

include/linux/memory-tiers.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/nodemask.h>
77
#include <linux/kref.h>
88
#include <linux/mmzone.h>
9+
#include <linux/notifier.h>
910
/*
1011
* Each tier cover a abstrace distance chunk size of 128
1112
*/
@@ -36,6 +37,9 @@ struct memory_dev_type *alloc_memory_type(int adistance);
3637
void put_memory_type(struct memory_dev_type *memtype);
3738
void init_node_memory_type(int node, struct memory_dev_type *default_type);
3839
void clear_node_memory_type(int node, struct memory_dev_type *memtype);
40+
int register_mt_adistance_algorithm(struct notifier_block *nb);
41+
int unregister_mt_adistance_algorithm(struct notifier_block *nb);
42+
int mt_calc_adistance(int node, int *adist);
3943
#ifdef CONFIG_MIGRATION
4044
int next_demotion_node(int node);
4145
void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
@@ -97,5 +101,20 @@ static inline bool node_is_toptier(int node)
97101
{
98102
return true;
99103
}
104+
105+
static inline int register_mt_adistance_algorithm(struct notifier_block *nb)
106+
{
107+
return 0;
108+
}
109+
110+
static inline int unregister_mt_adistance_algorithm(struct notifier_block *nb)
111+
{
112+
return 0;
113+
}
114+
115+
static inline int mt_calc_adistance(int node, int *adist)
116+
{
117+
return NOTIFY_DONE;
118+
}
100119
#endif /* CONFIG_NUMA */
101120
#endif /* _LINUX_MEMORY_TIERS_H */

mm/memory-tiers.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/kobject.h>
66
#include <linux/memory.h>
77
#include <linux/memory-tiers.h>
8+
#include <linux/notifier.h>
89

910
#include "internal.h"
1011

@@ -105,6 +106,8 @@ static int top_tier_adistance;
105106
static struct demotion_nodes *node_demotion __read_mostly;
106107
#endif /* CONFIG_MIGRATION */
107108

109+
static BLOCKING_NOTIFIER_HEAD(mt_adistance_algorithms);
110+
108111
static inline struct memory_tier *to_memory_tier(struct device *device)
109112
{
110113
return container_of(device, struct memory_tier, dev);
@@ -592,6 +595,62 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype)
592595
}
593596
EXPORT_SYMBOL_GPL(clear_node_memory_type);
594597

598+
/**
599+
* register_mt_adistance_algorithm() - Register memory tiering abstract distance algorithm
600+
* @nb: The notifier block which describe the algorithm
601+
*
602+
* Return: 0 on success, errno on error.
603+
*
604+
* Every memory tiering abstract distance algorithm provider needs to
605+
* register the algorithm with register_mt_adistance_algorithm(). To
606+
* calculate the abstract distance for a specified memory node, the
607+
* notifier function will be called unless some high priority
608+
* algorithm has provided result. The prototype of the notifier
609+
* function is as follows,
610+
*
611+
* int (*algorithm_notifier)(struct notifier_block *nb,
612+
* unsigned long nid, void *data);
613+
*
614+
* Where "nid" specifies the memory node, "data" is the pointer to the
615+
* returned abstract distance (that is, "int *adist"). If the
616+
* algorithm provides the result, NOTIFY_STOP should be returned.
617+
* Otherwise, return_value & %NOTIFY_STOP_MASK == 0 to allow the next
618+
* algorithm in the chain to provide the result.
619+
*/
620+
int register_mt_adistance_algorithm(struct notifier_block *nb)
621+
{
622+
return blocking_notifier_chain_register(&mt_adistance_algorithms, nb);
623+
}
624+
EXPORT_SYMBOL_GPL(register_mt_adistance_algorithm);
625+
626+
/**
627+
* unregister_mt_adistance_algorithm() - Unregister memory tiering abstract distance algorithm
628+
* @nb: the notifier block which describe the algorithm
629+
*
630+
* Return: 0 on success, errno on error.
631+
*/
632+
int unregister_mt_adistance_algorithm(struct notifier_block *nb)
633+
{
634+
return blocking_notifier_chain_unregister(&mt_adistance_algorithms, nb);
635+
}
636+
EXPORT_SYMBOL_GPL(unregister_mt_adistance_algorithm);
637+
638+
/**
639+
* mt_calc_adistance() - Calculate abstract distance with registered algorithms
640+
* @node: the node to calculate abstract distance for
641+
* @adist: the returned abstract distance
642+
*
643+
* Return: if return_value & %NOTIFY_STOP_MASK != 0, then some
644+
* abstract distance algorithm provides the result, and return it via
645+
* @adist. Otherwise, no algorithm can provide the result and @adist
646+
* will be kept as it is.
647+
*/
648+
int mt_calc_adistance(int node, int *adist)
649+
{
650+
return blocking_notifier_call_chain(&mt_adistance_algorithms, node, adist);
651+
}
652+
EXPORT_SYMBOL_GPL(mt_calc_adistance);
653+
595654
static int __meminit memtier_hotplug_callback(struct notifier_block *self,
596655
unsigned long action, void *_arg)
597656
{

0 commit comments

Comments
 (0)