]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * NUMA memory policies for Linux. | |
4 | * Copyright 2003,2004 Andi Kleen SuSE Labs | |
5 | */ | |
607ca46e DH |
6 | #ifndef _LINUX_MEMPOLICY_H |
7 | #define _LINUX_MEMPOLICY_H 1 | |
1da177e4 | 8 | |
8ca39e68 | 9 | #include <linux/sched.h> |
1da177e4 | 10 | #include <linux/mmzone.h> |
1da177e4 LT |
11 | #include <linux/slab.h> |
12 | #include <linux/rbtree.h> | |
13 | #include <linux/spinlock.h> | |
dfcd3c0d | 14 | #include <linux/nodemask.h> |
83d1674a | 15 | #include <linux/pagemap.h> |
607ca46e | 16 | #include <uapi/linux/mempolicy.h> |
1da177e4 | 17 | |
45b35a5c | 18 | struct mm_struct; |
1da177e4 | 19 | |
ddc1a5cb HD |
20 | #define NO_INTERLEAVE_INDEX (-1UL) /* use task il_prev for interleaving */ |
21 | ||
1da177e4 LT |
22 | #ifdef CONFIG_NUMA |
23 | ||
24 | /* | |
25 | * Describe a memory policy. | |
26 | * | |
27 | * A mempolicy can be either associated with a process or with a VMA. | |
28 | * For VMA related allocations the VMA policy is preferred, otherwise | |
29 | * the process policy is used. Interrupts ignore the memory policy | |
30 | * of the current process. | |
31 | * | |
f3f3416c | 32 | * Locking policy for interleave: |
1da177e4 LT |
33 | * In process context there is no locking because only the process accesses |
34 | * its own state. All vma manipulation is somewhat protected by a down_read on | |
c1e8d7c6 | 35 | * mmap_lock. |
1da177e4 LT |
36 | * |
37 | * Freeing policy: | |
19770b32 | 38 | * Mempolicy objects are reference counted. A mempolicy will be freed when |
f0be3d32 | 39 | * mpol_put() decrements the reference count to zero. |
1da177e4 | 40 | * |
846a16bf LS |
41 | * Duplicating policy objects: |
42 | * mpol_dup() allocates a new mempolicy and copies the specified mempolicy | |
19770b32 | 43 | * to the new storage. The reference count of the new object is initialized |
846a16bf | 44 | * to 1, representing the caller of mpol_dup(). |
1da177e4 LT |
45 | */ |
46 | struct mempolicy { | |
47 | atomic_t refcnt; | |
45c4745a | 48 | unsigned short mode; /* See MPOL_* above */ |
028fec41 | 49 | unsigned short flags; /* See set_mempolicy() MPOL_F_* above */ |
269fbe72 | 50 | nodemask_t nodes; /* interleave/bind/perfer */ |
c6018b4b | 51 | int home_node; /* Home node to use for MPOL_BIND and MPOL_PREFERRED_MANY */ |
269fbe72 | 52 | |
f5b087b5 DR |
53 | union { |
54 | nodemask_t cpuset_mems_allowed; /* relative to these nodes */ | |
55 | nodemask_t user_nodemask; /* nodemask passed by user */ | |
56 | } w; | |
1da177e4 LT |
57 | }; |
58 | ||
59 | /* | |
60 | * Support for managing mempolicy data objects (clone, copy, destroy) | |
61 | * The default fast path of a NULL MPOL_DEFAULT policy is always inlined. | |
62 | */ | |
63 | ||
f0be3d32 LS |
64 | extern void __mpol_put(struct mempolicy *pol); |
65 | static inline void mpol_put(struct mempolicy *pol) | |
1da177e4 LT |
66 | { |
67 | if (pol) | |
f0be3d32 | 68 | __mpol_put(pol); |
1da177e4 LT |
69 | } |
70 | ||
52cd3b07 LS |
71 | /* |
72 | * Does mempolicy pol need explicit unref after use? | |
73 | * Currently only needed for shared policies. | |
74 | */ | |
75 | static inline int mpol_needs_cond_ref(struct mempolicy *pol) | |
76 | { | |
77 | return (pol && (pol->flags & MPOL_F_SHARED)); | |
78 | } | |
79 | ||
80 | static inline void mpol_cond_put(struct mempolicy *pol) | |
81 | { | |
82 | if (mpol_needs_cond_ref(pol)) | |
83 | __mpol_put(pol); | |
84 | } | |
85 | ||
846a16bf LS |
86 | extern struct mempolicy *__mpol_dup(struct mempolicy *pol); |
87 | static inline struct mempolicy *mpol_dup(struct mempolicy *pol) | |
1da177e4 LT |
88 | { |
89 | if (pol) | |
846a16bf | 90 | pol = __mpol_dup(pol); |
1da177e4 LT |
91 | return pol; |
92 | } | |
93 | ||
1da177e4 LT |
94 | static inline void mpol_get(struct mempolicy *pol) |
95 | { | |
96 | if (pol) | |
97 | atomic_inc(&pol->refcnt); | |
98 | } | |
99 | ||
fcfb4dcc KM |
100 | extern bool __mpol_equal(struct mempolicy *a, struct mempolicy *b); |
101 | static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b) | |
1da177e4 LT |
102 | { |
103 | if (a == b) | |
fcfb4dcc | 104 | return true; |
1da177e4 LT |
105 | return __mpol_equal(a, b); |
106 | } | |
1da177e4 | 107 | |
1da177e4 LT |
108 | /* |
109 | * Tree of shared policies for a shared memory region. | |
1da177e4 | 110 | */ |
1da177e4 LT |
111 | struct shared_policy { |
112 | struct rb_root root; | |
4a8c7bb5 | 113 | rwlock_t lock; |
1da177e4 | 114 | }; |
93397c3b HD |
115 | struct sp_node { |
116 | struct rb_node nd; | |
117 | pgoff_t start, end; | |
118 | struct mempolicy *policy; | |
119 | }; | |
1da177e4 | 120 | |
ef0855d3 | 121 | int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst); |
71fe804b | 122 | void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol); |
c36f6e6d HD |
123 | int mpol_set_shared_policy(struct shared_policy *sp, |
124 | struct vm_area_struct *vma, struct mempolicy *mpol); | |
125 | void mpol_free_shared_policy(struct shared_policy *sp); | |
1da177e4 | 126 | struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp, |
93397c3b | 127 | pgoff_t idx); |
1da177e4 | 128 | |
74d2c3a0 ON |
129 | struct mempolicy *get_task_policy(struct task_struct *p); |
130 | struct mempolicy *__get_vma_policy(struct vm_area_struct *vma, | |
ddc1a5cb HD |
131 | unsigned long addr, pgoff_t *ilx); |
132 | struct mempolicy *get_vma_policy(struct vm_area_struct *vma, | |
133 | unsigned long addr, int order, pgoff_t *ilx); | |
6b6482bb | 134 | bool vma_policy_mof(struct vm_area_struct *vma); |
d98f6cb6 | 135 | |
1da177e4 LT |
136 | extern void numa_default_policy(void); |
137 | extern void numa_policy_init(void); | |
213980c0 | 138 | extern void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new); |
4225399a | 139 | extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new); |
4225399a | 140 | |
04ec6264 | 141 | extern int huge_node(struct vm_area_struct *vma, |
19770b32 MG |
142 | unsigned long addr, gfp_t gfp_flags, |
143 | struct mempolicy **mpol, nodemask_t **nodemask); | |
06808b08 | 144 | extern bool init_nodemask_of_mempolicy(nodemask_t *mask); |
b26e517a | 145 | extern bool mempolicy_in_oom_domain(struct task_struct *tsk, |
6f48d0eb | 146 | const nodemask_t *mask); |
2a389610 | 147 | extern unsigned int mempolicy_slab_node(void); |
1da177e4 | 148 | |
2f6726e5 | 149 | extern enum zone_type policy_zone; |
4be38e35 | 150 | |
2f6726e5 | 151 | static inline void check_highest_zone(enum zone_type k) |
4be38e35 | 152 | { |
b377fd39 | 153 | if (k > policy_zone && k != ZONE_MOVABLE) |
4be38e35 CL |
154 | policy_zone = k; |
155 | } | |
156 | ||
0ce72d4f AM |
157 | int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from, |
158 | const nodemask_t *to, int flags); | |
39743889 | 159 | |
095f1fc4 LS |
160 | |
161 | #ifdef CONFIG_TMPFS | |
a7a88b23 | 162 | extern int mpol_parse_str(char *str, struct mempolicy **mpol); |
13057efb | 163 | #endif |
095f1fc4 | 164 | |
948927ee | 165 | extern void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol); |
83d1674a GS |
166 | |
167 | /* Check if a vma is migratable */ | |
20ca87f2 | 168 | extern bool vma_migratable(struct vm_area_struct *vma); |
83d1674a | 169 | |
f8fd525b DT |
170 | int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, |
171 | unsigned long addr); | |
c11600e4 | 172 | extern void mpol_put_task_policy(struct task_struct *); |
771fb4d8 | 173 | |
cfcaa66f BW |
174 | static inline bool mpol_is_preferred_many(struct mempolicy *pol) |
175 | { | |
176 | return (pol->mode == MPOL_PREFERRED_MANY); | |
177 | } | |
178 | ||
d2226ebd | 179 | extern bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone); |
cfcaa66f | 180 | |
1da177e4 LT |
181 | #else |
182 | ||
183 | struct mempolicy {}; | |
184 | ||
ddc1a5cb HD |
185 | static inline struct mempolicy *get_task_policy(struct task_struct *p) |
186 | { | |
187 | return NULL; | |
188 | } | |
189 | ||
fcfb4dcc | 190 | static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b) |
1da177e4 | 191 | { |
fcfb4dcc | 192 | return true; |
1da177e4 | 193 | } |
1da177e4 | 194 | |
c36f6e6d | 195 | static inline void mpol_put(struct mempolicy *pol) |
1da177e4 LT |
196 | { |
197 | } | |
198 | ||
52cd3b07 LS |
199 | static inline void mpol_cond_put(struct mempolicy *pol) |
200 | { | |
201 | } | |
202 | ||
1da177e4 LT |
203 | static inline void mpol_get(struct mempolicy *pol) |
204 | { | |
205 | } | |
206 | ||
1da177e4 LT |
207 | struct shared_policy {}; |
208 | ||
71fe804b LS |
209 | static inline void mpol_shared_policy_init(struct shared_policy *sp, |
210 | struct mempolicy *mpol) | |
1da177e4 LT |
211 | { |
212 | } | |
213 | ||
c36f6e6d | 214 | static inline void mpol_free_shared_policy(struct shared_policy *sp) |
1da177e4 LT |
215 | { |
216 | } | |
217 | ||
75edd345 | 218 | static inline struct mempolicy * |
93397c3b | 219 | mpol_shared_policy_lookup(struct shared_policy *sp, pgoff_t idx) |
75edd345 HD |
220 | { |
221 | return NULL; | |
222 | } | |
223 | ||
ddc1a5cb HD |
224 | static inline struct mempolicy *get_vma_policy(struct vm_area_struct *vma, |
225 | unsigned long addr, int order, pgoff_t *ilx) | |
226 | { | |
227 | *ilx = 0; | |
228 | return NULL; | |
229 | } | |
230 | ||
ef0855d3 ON |
231 | static inline int |
232 | vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst) | |
233 | { | |
234 | return 0; | |
235 | } | |
1da177e4 LT |
236 | |
237 | static inline void numa_policy_init(void) | |
238 | { | |
239 | } | |
240 | ||
241 | static inline void numa_default_policy(void) | |
242 | { | |
243 | } | |
244 | ||
74cb2155 | 245 | static inline void mpol_rebind_task(struct task_struct *tsk, |
213980c0 | 246 | const nodemask_t *new) |
68860ec1 PJ |
247 | { |
248 | } | |
249 | ||
4225399a PJ |
250 | static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new) |
251 | { | |
252 | } | |
253 | ||
04ec6264 | 254 | static inline int huge_node(struct vm_area_struct *vma, |
19770b32 MG |
255 | unsigned long addr, gfp_t gfp_flags, |
256 | struct mempolicy **mpol, nodemask_t **nodemask) | |
5da7ca86 | 257 | { |
19770b32 MG |
258 | *mpol = NULL; |
259 | *nodemask = NULL; | |
04ec6264 | 260 | return 0; |
5da7ca86 CL |
261 | } |
262 | ||
6f48d0eb DR |
263 | static inline bool init_nodemask_of_mempolicy(nodemask_t *m) |
264 | { | |
265 | return false; | |
266 | } | |
267 | ||
0ce72d4f AM |
268 | static inline int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from, |
269 | const nodemask_t *to, int flags) | |
45b07ef3 PJ |
270 | { |
271 | return 0; | |
272 | } | |
273 | ||
4be38e35 CL |
274 | static inline void check_highest_zone(int k) |
275 | { | |
276 | } | |
095f1fc4 LS |
277 | |
278 | #ifdef CONFIG_TMPFS | |
a7a88b23 | 279 | static inline int mpol_parse_str(char *str, struct mempolicy **mpol) |
095f1fc4 | 280 | { |
71fe804b | 281 | return 1; /* error */ |
095f1fc4 | 282 | } |
13057efb | 283 | #endif |
095f1fc4 | 284 | |
75c70128 | 285 | static inline int mpol_misplaced(struct folio *folio, |
f8fd525b | 286 | struct vm_fault *vmf, |
771fb4d8 LS |
287 | unsigned long address) |
288 | { | |
289 | return -1; /* no node preference */ | |
290 | } | |
291 | ||
c11600e4 DR |
292 | static inline void mpol_put_task_policy(struct task_struct *task) |
293 | { | |
294 | } | |
8ca39e68 | 295 | |
cfcaa66f BW |
296 | static inline bool mpol_is_preferred_many(struct mempolicy *pol) |
297 | { | |
298 | return false; | |
299 | } | |
300 | ||
1da177e4 | 301 | #endif /* CONFIG_NUMA */ |
1da177e4 | 302 | #endif |