Commit | Line | Data |
---|---|---|
992bf775 AK |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef _LINUX_MEMORY_TIERS_H | |
3 | #define _LINUX_MEMORY_TIERS_H | |
4 | ||
7b88bda3 AK |
5 | #include <linux/types.h> |
6 | #include <linux/nodemask.h> | |
7 | #include <linux/kref.h> | |
32008027 | 8 | #include <linux/mmzone.h> |
992bf775 AK |
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 | ||
7b88bda3 AK |
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; | |
7b88bda3 AK |
31 | }; |
32 | ||
91952440 | 33 | #ifdef CONFIG_NUMA |
91952440 | 34 | extern bool numa_demotion_enabled; |
7b88bda3 AK |
35 | struct memory_dev_type *alloc_memory_type(int adistance); |
36 | void destroy_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); | |
6c542ab7 AK |
39 | #ifdef CONFIG_MIGRATION |
40 | int next_demotion_node(int node); | |
32008027 | 41 | void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); |
467b171a | 42 | bool node_is_toptier(int node); |
6c542ab7 AK |
43 | #else |
44 | static inline int next_demotion_node(int node) | |
45 | { | |
46 | return NUMA_NO_NODE; | |
47 | } | |
32008027 JG |
48 | |
49 | static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) | |
50 | { | |
51 | *targets = NODE_MASK_NONE; | |
52 | } | |
467b171a AK |
53 | |
54 | static inline bool node_is_toptier(int node) | |
55 | { | |
56 | return true; | |
57 | } | |
6c542ab7 | 58 | #endif |
91952440 AK |
59 | |
60 | #else | |
61 | ||
62 | #define numa_demotion_enabled false | |
7b88bda3 AK |
63 | /* |
64 | * CONFIG_NUMA implementation returns non NULL error. | |
65 | */ | |
66 | static inline struct memory_dev_type *alloc_memory_type(int adistance) | |
67 | { | |
68 | return NULL; | |
69 | } | |
70 | ||
71 | static inline void destroy_memory_type(struct memory_dev_type *memtype) | |
72 | { | |
73 | ||
74 | } | |
75 | ||
76 | static inline void init_node_memory_type(int node, struct memory_dev_type *default_type) | |
77 | { | |
78 | ||
79 | } | |
80 | ||
81 | static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype) | |
82 | { | |
83 | ||
84 | } | |
6c542ab7 AK |
85 | |
86 | static inline int next_demotion_node(int node) | |
87 | { | |
88 | return NUMA_NO_NODE; | |
89 | } | |
32008027 JG |
90 | |
91 | static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) | |
92 | { | |
93 | *targets = NODE_MASK_NONE; | |
94 | } | |
467b171a AK |
95 | |
96 | static inline bool node_is_toptier(int node) | |
97 | { | |
98 | return true; | |
99 | } | |
91952440 | 100 | #endif /* CONFIG_NUMA */ |
992bf775 | 101 | #endif /* _LINUX_MEMORY_TIERS_H */ |