1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MEMORY_TIERS_H
3 #define _LINUX_MEMORY_TIERS_H
4
5 #include <linux/types.h>
6 #include <linux/nodemask.h>
7 #include <linux/kref.h>
8 #include <linux/mmzone.h>
9 /*
10 * Each tier cover a abstrace distance chunk size of 128
11 */
12 #define MEMTIER_CHUNK_BITS 7
13 #define MEMTIER_CHUNK_SIZE (1 << MEMTIER_CHUNK_BITS)
14 /*
15 * Smaller abstract distance values imply faster (higher) memory tiers. Offset
16 * the DRAM adistance so that we can accommodate devices with a slightly lower
17 * adistance value (slightly faster) than default DRAM adistance to be part of
18 * the same memory tier.
19 */
20 #define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1))
21
22 struct memory_tier;
23 struct memory_dev_type {
24 /* list of memory types that are part of same tier as this type */
25 struct list_head tier_sibiling;
26 /* abstract distance for this specific memory type */
27 int adistance;
28 /* Nodes of same abstract distance */
29 nodemask_t nodes;
30 struct kref kref;
31 };
32
33 #ifdef CONFIG_NUMA
34 extern bool numa_demotion_enabled;
35 struct memory_dev_type *alloc_memory_type(int adistance);
36 void put_memory_type(struct memory_dev_type *memtype);
37 void init_node_memory_type(int node, struct memory_dev_type *default_type);
38 void clear_node_memory_type(int node, struct memory_dev_type *memtype);
39 #ifdef CONFIG_MIGRATION
40 int next_demotion_node(int node);
41 void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
42 bool node_is_toptier(int node);
43 #else
next_demotion_node(int node)44 static inline int next_demotion_node(int node)
45 {
46 return NUMA_NO_NODE;
47 }
48
node_get_allowed_targets(pg_data_t * pgdat,nodemask_t * targets)49 static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
50 {
51 *targets = NODE_MASK_NONE;
52 }
53
node_is_toptier(int node)54 static inline bool node_is_toptier(int node)
55 {
56 return true;
57 }
58 #endif
59
60 #else
61
62 #define numa_demotion_enabled false
63 /*
64 * CONFIG_NUMA implementation returns non NULL error.
65 */
alloc_memory_type(int adistance)66 static inline struct memory_dev_type *alloc_memory_type(int adistance)
67 {
68 return NULL;
69 }
70
put_memory_type(struct memory_dev_type * memtype)71 static inline void put_memory_type(struct memory_dev_type *memtype)
72 {
73
74 }
75
init_node_memory_type(int node,struct memory_dev_type * default_type)76 static inline void init_node_memory_type(int node, struct memory_dev_type *default_type)
77 {
78
79 }
80
clear_node_memory_type(int node,struct memory_dev_type * memtype)81 static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype)
82 {
83
84 }
85
next_demotion_node(int node)86 static inline int next_demotion_node(int node)
87 {
88 return NUMA_NO_NODE;
89 }
90
node_get_allowed_targets(pg_data_t * pgdat,nodemask_t * targets)91 static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
92 {
93 *targets = NODE_MASK_NONE;
94 }
95
node_is_toptier(int node)96 static inline bool node_is_toptier(int node)
97 {
98 return true;
99 }
100 #endif /* CONFIG_NUMA */
101 #endif /* _LINUX_MEMORY_TIERS_H */
102