Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_MEMPOLICY_H |
2 | #define _LINUX_MEMPOLICY_H 1 | |
3 | ||
4 | #include <linux/errno.h> | |
5 | ||
6 | /* | |
7 | * NUMA memory policies for Linux. | |
8 | * Copyright 2003,2004 Andi Kleen SuSE Labs | |
9 | */ | |
10 | ||
028fec41 DR |
11 | /* |
12 | * Both the MPOL_* mempolicy mode and the MPOL_F_* optional mode flags are | |
13 | * passed by the user to either set_mempolicy() or mbind() in an 'int' actual. | |
14 | * The MPOL_MODE_FLAGS macro determines the legal set of optional mode flags. | |
15 | */ | |
16 | ||
1da177e4 | 17 | /* Policies */ |
a3b51e01 DR |
18 | enum { |
19 | MPOL_DEFAULT, | |
20 | MPOL_PREFERRED, | |
21 | MPOL_BIND, | |
22 | MPOL_INTERLEAVE, | |
23 | MPOL_MAX, /* always last member of enum */ | |
24 | }; | |
1da177e4 | 25 | |
028fec41 | 26 | /* Flags for set_mempolicy */ |
f5b087b5 | 27 | #define MPOL_F_STATIC_NODES (1 << 15) |
4c50bc01 | 28 | #define MPOL_F_RELATIVE_NODES (1 << 14) |
f5b087b5 | 29 | |
028fec41 DR |
30 | /* |
31 | * MPOL_MODE_FLAGS is the union of all possible optional mode flags passed to | |
32 | * either set_mempolicy() or mbind(). | |
33 | */ | |
4c50bc01 | 34 | #define MPOL_MODE_FLAGS (MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES) |
028fec41 DR |
35 | |
36 | /* Flags for get_mempolicy */ | |
1da177e4 LT |
37 | #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */ |
38 | #define MPOL_F_ADDR (1<<1) /* look up vma using address */ | |
754af6f5 | 39 | #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */ |
1da177e4 LT |
40 | |
41 | /* Flags for mbind */ | |
42 | #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */ | |
dc9aa5b9 CL |
43 | #define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */ |
44 | #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */ | |
45 | #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */ | |
1da177e4 | 46 | |
aab0b102 LS |
47 | /* |
48 | * Internal flags that share the struct mempolicy flags word with | |
49 | * "mode flags". These flags are allocated from bit 0 up, as they | |
50 | * are never OR'ed into the mode in mempolicy API arguments. | |
51 | */ | |
52 | #define MPOL_F_SHARED (1 << 0) /* identify shared policies */ | |
fc36b8d3 | 53 | #define MPOL_F_LOCAL (1 << 1) /* preferred local allocation */ |
aab0b102 | 54 | |
1da177e4 LT |
55 | #ifdef __KERNEL__ |
56 | ||
1da177e4 | 57 | #include <linux/mmzone.h> |
1da177e4 LT |
58 | #include <linux/slab.h> |
59 | #include <linux/rbtree.h> | |
60 | #include <linux/spinlock.h> | |
dfcd3c0d | 61 | #include <linux/nodemask.h> |
1da177e4 | 62 | |
45b35a5c | 63 | struct mm_struct; |
1da177e4 LT |
64 | |
65 | #ifdef CONFIG_NUMA | |
66 | ||
67 | /* | |
68 | * Describe a memory policy. | |
69 | * | |
70 | * A mempolicy can be either associated with a process or with a VMA. | |
71 | * For VMA related allocations the VMA policy is preferred, otherwise | |
72 | * the process policy is used. Interrupts ignore the memory policy | |
73 | * of the current process. | |
74 | * | |
75 | * Locking policy for interlave: | |
76 | * In process context there is no locking because only the process accesses | |
77 | * its own state. All vma manipulation is somewhat protected by a down_read on | |
b8072f09 | 78 | * mmap_sem. |
1da177e4 LT |
79 | * |
80 | * Freeing policy: | |
19770b32 | 81 | * Mempolicy objects are reference counted. A mempolicy will be freed when |
f0be3d32 | 82 | * mpol_put() decrements the reference count to zero. |
1da177e4 | 83 | * |
846a16bf LS |
84 | * Duplicating policy objects: |
85 | * mpol_dup() allocates a new mempolicy and copies the specified mempolicy | |
19770b32 | 86 | * to the new storage. The reference count of the new object is initialized |
846a16bf | 87 | * to 1, representing the caller of mpol_dup(). |
1da177e4 LT |
88 | */ |
89 | struct mempolicy { | |
90 | atomic_t refcnt; | |
45c4745a | 91 | unsigned short mode; /* See MPOL_* above */ |
028fec41 | 92 | unsigned short flags; /* See set_mempolicy() MPOL_F_* above */ |
1da177e4 | 93 | union { |
1da177e4 | 94 | short preferred_node; /* preferred */ |
19770b32 | 95 | nodemask_t nodes; /* interleave/bind */ |
1da177e4 LT |
96 | /* undefined for default */ |
97 | } v; | |
f5b087b5 DR |
98 | union { |
99 | nodemask_t cpuset_mems_allowed; /* relative to these nodes */ | |
100 | nodemask_t user_nodemask; /* nodemask passed by user */ | |
101 | } w; | |
1da177e4 LT |
102 | }; |
103 | ||
104 | /* | |
105 | * Support for managing mempolicy data objects (clone, copy, destroy) | |
106 | * The default fast path of a NULL MPOL_DEFAULT policy is always inlined. | |
107 | */ | |
108 | ||
f0be3d32 LS |
109 | extern void __mpol_put(struct mempolicy *pol); |
110 | static inline void mpol_put(struct mempolicy *pol) | |
1da177e4 LT |
111 | { |
112 | if (pol) | |
f0be3d32 | 113 | __mpol_put(pol); |
1da177e4 LT |
114 | } |
115 | ||
52cd3b07 LS |
116 | /* |
117 | * Does mempolicy pol need explicit unref after use? | |
118 | * Currently only needed for shared policies. | |
119 | */ | |
120 | static inline int mpol_needs_cond_ref(struct mempolicy *pol) | |
121 | { | |
122 | return (pol && (pol->flags & MPOL_F_SHARED)); | |
123 | } | |
124 | ||
125 | static inline void mpol_cond_put(struct mempolicy *pol) | |
126 | { | |
127 | if (mpol_needs_cond_ref(pol)) | |
128 | __mpol_put(pol); | |
129 | } | |
130 | ||
131 | extern struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol, | |
132 | struct mempolicy *frompol); | |
133 | static inline struct mempolicy *mpol_cond_copy(struct mempolicy *tompol, | |
134 | struct mempolicy *frompol) | |
135 | { | |
136 | if (!frompol) | |
137 | return frompol; | |
138 | return __mpol_cond_copy(tompol, frompol); | |
139 | } | |
140 | ||
846a16bf LS |
141 | extern struct mempolicy *__mpol_dup(struct mempolicy *pol); |
142 | static inline struct mempolicy *mpol_dup(struct mempolicy *pol) | |
1da177e4 LT |
143 | { |
144 | if (pol) | |
846a16bf | 145 | pol = __mpol_dup(pol); |
1da177e4 LT |
146 | return pol; |
147 | } | |
148 | ||
149 | #define vma_policy(vma) ((vma)->vm_policy) | |
150 | #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol)) | |
151 | ||
152 | static inline void mpol_get(struct mempolicy *pol) | |
153 | { | |
154 | if (pol) | |
155 | atomic_inc(&pol->refcnt); | |
156 | } | |
157 | ||
158 | extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b); | |
159 | static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b) | |
160 | { | |
161 | if (a == b) | |
162 | return 1; | |
163 | return __mpol_equal(a, b); | |
164 | } | |
1da177e4 | 165 | |
1da177e4 LT |
166 | /* |
167 | * Tree of shared policies for a shared memory region. | |
168 | * Maintain the policies in a pseudo mm that contains vmas. The vmas | |
169 | * carry the policy. As a special twist the pseudo mm is indexed in pages, not | |
170 | * bytes, so that we can work with shared memory segments bigger than | |
171 | * unsigned long. | |
172 | */ | |
173 | ||
174 | struct sp_node { | |
175 | struct rb_node nd; | |
176 | unsigned long start, end; | |
177 | struct mempolicy *policy; | |
178 | }; | |
179 | ||
180 | struct shared_policy { | |
181 | struct rb_root root; | |
182 | spinlock_t lock; | |
183 | }; | |
184 | ||
45c4745a | 185 | void mpol_shared_policy_init(struct shared_policy *info, unsigned short mode, |
028fec41 | 186 | unsigned short flags, nodemask_t *nodes); |
1da177e4 LT |
187 | int mpol_set_shared_policy(struct shared_policy *info, |
188 | struct vm_area_struct *vma, | |
189 | struct mempolicy *new); | |
190 | void mpol_free_shared_policy(struct shared_policy *p); | |
191 | struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp, | |
192 | unsigned long idx); | |
193 | ||
194 | extern void numa_default_policy(void); | |
195 | extern void numa_policy_init(void); | |
74cb2155 PJ |
196 | extern void mpol_rebind_task(struct task_struct *tsk, |
197 | const nodemask_t *new); | |
4225399a | 198 | extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new); |
c61afb18 | 199 | extern void mpol_fix_fork_child_flag(struct task_struct *p); |
4225399a | 200 | |
5da7ca86 | 201 | extern struct zonelist *huge_zonelist(struct vm_area_struct *vma, |
19770b32 MG |
202 | unsigned long addr, gfp_t gfp_flags, |
203 | struct mempolicy **mpol, nodemask_t **nodemask); | |
dc85da15 | 204 | extern unsigned slab_node(struct mempolicy *policy); |
1da177e4 | 205 | |
2f6726e5 | 206 | extern enum zone_type policy_zone; |
4be38e35 | 207 | |
2f6726e5 | 208 | static inline void check_highest_zone(enum zone_type k) |
4be38e35 | 209 | { |
b377fd39 | 210 | if (k > policy_zone && k != ZONE_MOVABLE) |
4be38e35 CL |
211 | policy_zone = k; |
212 | } | |
213 | ||
39743889 CL |
214 | int do_migrate_pages(struct mm_struct *mm, |
215 | const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags); | |
216 | ||
1da177e4 LT |
217 | #else |
218 | ||
219 | struct mempolicy {}; | |
220 | ||
221 | static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b) | |
222 | { | |
223 | return 1; | |
224 | } | |
1da177e4 | 225 | |
f0be3d32 | 226 | static inline void mpol_put(struct mempolicy *p) |
1da177e4 LT |
227 | { |
228 | } | |
229 | ||
52cd3b07 LS |
230 | static inline void mpol_cond_put(struct mempolicy *pol) |
231 | { | |
232 | } | |
233 | ||
234 | static inline struct mempolicy *mpol_cond_copy(struct mempolicy *to, | |
235 | struct mempolicy *from) | |
236 | { | |
237 | return from; | |
238 | } | |
239 | ||
1da177e4 LT |
240 | static inline void mpol_get(struct mempolicy *pol) |
241 | { | |
242 | } | |
243 | ||
846a16bf | 244 | static inline struct mempolicy *mpol_dup(struct mempolicy *old) |
1da177e4 LT |
245 | { |
246 | return NULL; | |
247 | } | |
248 | ||
1da177e4 LT |
249 | struct shared_policy {}; |
250 | ||
251 | static inline int mpol_set_shared_policy(struct shared_policy *info, | |
252 | struct vm_area_struct *vma, | |
253 | struct mempolicy *new) | |
254 | { | |
255 | return -EINVAL; | |
256 | } | |
257 | ||
7339ff83 | 258 | static inline void mpol_shared_policy_init(struct shared_policy *info, |
45c4745a | 259 | unsigned short mode, unsigned short flags, nodemask_t *nodes) |
1da177e4 LT |
260 | { |
261 | } | |
262 | ||
263 | static inline void mpol_free_shared_policy(struct shared_policy *p) | |
264 | { | |
265 | } | |
266 | ||
267 | static inline struct mempolicy * | |
268 | mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx) | |
269 | { | |
270 | return NULL; | |
271 | } | |
272 | ||
273 | #define vma_policy(vma) NULL | |
274 | #define vma_set_policy(vma, pol) do {} while(0) | |
275 | ||
276 | static inline void numa_policy_init(void) | |
277 | { | |
278 | } | |
279 | ||
280 | static inline void numa_default_policy(void) | |
281 | { | |
282 | } | |
283 | ||
74cb2155 | 284 | static inline void mpol_rebind_task(struct task_struct *tsk, |
68860ec1 PJ |
285 | const nodemask_t *new) |
286 | { | |
287 | } | |
288 | ||
4225399a PJ |
289 | static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new) |
290 | { | |
291 | } | |
292 | ||
c61afb18 PJ |
293 | static inline void mpol_fix_fork_child_flag(struct task_struct *p) |
294 | { | |
295 | } | |
296 | ||
5da7ca86 | 297 | static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma, |
19770b32 MG |
298 | unsigned long addr, gfp_t gfp_flags, |
299 | struct mempolicy **mpol, nodemask_t **nodemask) | |
5da7ca86 | 300 | { |
19770b32 MG |
301 | *mpol = NULL; |
302 | *nodemask = NULL; | |
0e88460d | 303 | return node_zonelist(0, gfp_flags); |
5da7ca86 CL |
304 | } |
305 | ||
45b07ef3 PJ |
306 | static inline int do_migrate_pages(struct mm_struct *mm, |
307 | const nodemask_t *from_nodes, | |
308 | const nodemask_t *to_nodes, int flags) | |
309 | { | |
310 | return 0; | |
311 | } | |
312 | ||
4be38e35 CL |
313 | static inline void check_highest_zone(int k) |
314 | { | |
315 | } | |
1da177e4 LT |
316 | #endif /* CONFIG_NUMA */ |
317 | #endif /* __KERNEL__ */ | |
318 | ||
319 | #endif |