]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/mempolicy.h
Merge remote-tracking branch 'signal/for-next'
[karo-tx-linux.git] / include / linux / mempolicy.h
1 /*
2  * NUMA memory policies for Linux.
3  * Copyright 2003,2004 Andi Kleen SuSE Labs
4  */
5 #ifndef _LINUX_MEMPOLICY_H
6 #define _LINUX_MEMPOLICY_H 1
7
8 #include <linux/mmzone.h>
9 #include <linux/slab.h>
10 #include <linux/rbtree.h>
11 #include <linux/spinlock.h>
12 #include <linux/nodemask.h>
13 #include <linux/pagemap.h>
14 #include <uapi/linux/mempolicy.h>
15
16 struct mm_struct;
17
18 #ifdef CONFIG_NUMA
19
20 /*
21  * Describe a memory policy.
22  *
23  * A mempolicy can be either associated with a process or with a VMA.
24  * For VMA related allocations the VMA policy is preferred, otherwise
25  * the process policy is used. Interrupts ignore the memory policy
26  * of the current process.
27  *
28  * Locking policy for interlave:
29  * In process context there is no locking because only the process accesses
30  * its own state. All vma manipulation is somewhat protected by a down_read on
31  * mmap_sem.
32  *
33  * Freeing policy:
34  * Mempolicy objects are reference counted.  A mempolicy will be freed when
35  * mpol_put() decrements the reference count to zero.
36  *
37  * Duplicating policy objects:
38  * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
39  * to the new storage.  The reference count of the new object is initialized
40  * to 1, representing the caller of mpol_dup().
41  */
42 struct mempolicy {
43         atomic_t refcnt;
44         unsigned short mode;    /* See MPOL_* above */
45         unsigned short flags;   /* See set_mempolicy() MPOL_F_* above */
46         union {
47                 short            preferred_node; /* preferred */
48                 nodemask_t       nodes;         /* interleave/bind */
49                 /* undefined for default */
50         } v;
51         union {
52                 nodemask_t cpuset_mems_allowed; /* relative to these nodes */
53                 nodemask_t user_nodemask;       /* nodemask passed by user */
54         } w;
55 };
56
57 /*
58  * Support for managing mempolicy data objects (clone, copy, destroy)
59  * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
60  */
61
62 extern void __mpol_put(struct mempolicy *pol);
63 static inline void mpol_put(struct mempolicy *pol)
64 {
65         if (pol)
66                 __mpol_put(pol);
67 }
68
69 /*
70  * Does mempolicy pol need explicit unref after use?
71  * Currently only needed for shared policies.
72  */
73 static inline int mpol_needs_cond_ref(struct mempolicy *pol)
74 {
75         return (pol && (pol->flags & MPOL_F_SHARED));
76 }
77
78 static inline void mpol_cond_put(struct mempolicy *pol)
79 {
80         if (mpol_needs_cond_ref(pol))
81                 __mpol_put(pol);
82 }
83
84 extern struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol,
85                                           struct mempolicy *frompol);
86 static inline struct mempolicy *mpol_cond_copy(struct mempolicy *tompol,
87                                                 struct mempolicy *frompol)
88 {
89         if (!frompol)
90                 return frompol;
91         return __mpol_cond_copy(tompol, frompol);
92 }
93
94 extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
95 static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
96 {
97         if (pol)
98                 pol = __mpol_dup(pol);
99         return pol;
100 }
101
102 #define vma_policy(vma) ((vma)->vm_policy)
103 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
104
105 static inline void mpol_get(struct mempolicy *pol)
106 {
107         if (pol)
108                 atomic_inc(&pol->refcnt);
109 }
110
111 extern bool __mpol_equal(struct mempolicy *a, struct mempolicy *b);
112 static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b)
113 {
114         if (a == b)
115                 return true;
116         return __mpol_equal(a, b);
117 }
118
119 /*
120  * Tree of shared policies for a shared memory region.
121  * Maintain the policies in a pseudo mm that contains vmas. The vmas
122  * carry the policy. As a special twist the pseudo mm is indexed in pages, not
123  * bytes, so that we can work with shared memory segments bigger than
124  * unsigned long.
125  */
126
127 struct sp_node {
128         struct rb_node nd;
129         unsigned long start, end;
130         struct mempolicy *policy;
131 };
132
133 struct shared_policy {
134         struct rb_root root;
135         struct mutex mutex;
136 };
137
138 void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol);
139 int mpol_set_shared_policy(struct shared_policy *info,
140                                 struct vm_area_struct *vma,
141                                 struct mempolicy *new);
142 void mpol_free_shared_policy(struct shared_policy *p);
143 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
144                                             unsigned long idx);
145
146 struct mempolicy *get_vma_policy(struct task_struct *tsk,
147                 struct vm_area_struct *vma, unsigned long addr);
148
149 extern void numa_default_policy(void);
150 extern void numa_policy_init(void);
151 extern void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new,
152                                 enum mpol_rebind_step step);
153 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
154 extern void mpol_fix_fork_child_flag(struct task_struct *p);
155
156 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
157                                 unsigned long addr, gfp_t gfp_flags,
158                                 struct mempolicy **mpol, nodemask_t **nodemask);
159 extern bool init_nodemask_of_mempolicy(nodemask_t *mask);
160 extern bool mempolicy_nodemask_intersects(struct task_struct *tsk,
161                                 const nodemask_t *mask);
162 extern unsigned slab_node(void);
163
164 extern enum zone_type policy_zone;
165
166 static inline void check_highest_zone(enum zone_type k)
167 {
168         if (k > policy_zone && k != ZONE_MOVABLE)
169                 policy_zone = k;
170 }
171
172 int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
173                      const nodemask_t *to, int flags);
174
175
176 #ifdef CONFIG_TMPFS
177 extern int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context);
178 #endif
179
180 extern int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol,
181                         int no_context);
182
183 /* Check if a vma is migratable */
184 static inline int vma_migratable(struct vm_area_struct *vma)
185 {
186         if (vma->vm_flags & (VM_IO | VM_HUGETLB | VM_PFNMAP))
187                 return 0;
188         /*
189          * Migration allocates pages in the highest zone. If we cannot
190          * do so then migration (at least from node to node) is not
191          * possible.
192          */
193         if (vma->vm_file &&
194                 gfp_zone(mapping_gfp_mask(vma->vm_file->f_mapping))
195                                                                 < policy_zone)
196                         return 0;
197         return 1;
198 }
199
200 extern int mpol_misplaced(struct page *, struct vm_area_struct *, unsigned long);
201
202 #else /* CONFIG_NUMA */
203
204 struct mempolicy {};
205
206 static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b)
207 {
208         return true;
209 }
210
211 static inline void mpol_put(struct mempolicy *p)
212 {
213 }
214
215 static inline void mpol_cond_put(struct mempolicy *pol)
216 {
217 }
218
219 static inline struct mempolicy *mpol_cond_copy(struct mempolicy *to,
220                                                 struct mempolicy *from)
221 {
222         return from;
223 }
224
225 static inline void mpol_get(struct mempolicy *pol)
226 {
227 }
228
229 static inline struct mempolicy *mpol_dup(struct mempolicy *old)
230 {
231         return NULL;
232 }
233
234 struct shared_policy {};
235
236 static inline int mpol_set_shared_policy(struct shared_policy *info,
237                                         struct vm_area_struct *vma,
238                                         struct mempolicy *new)
239 {
240         return -EINVAL;
241 }
242
243 static inline void mpol_shared_policy_init(struct shared_policy *sp,
244                                                 struct mempolicy *mpol)
245 {
246 }
247
248 static inline void mpol_free_shared_policy(struct shared_policy *p)
249 {
250 }
251
252 static inline struct mempolicy *
253 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
254 {
255         return NULL;
256 }
257
258 #define vma_policy(vma) NULL
259 #define vma_set_policy(vma, pol) do {} while(0)
260
261 static inline void numa_policy_init(void)
262 {
263 }
264
265 static inline void numa_default_policy(void)
266 {
267 }
268
269 static inline void mpol_rebind_task(struct task_struct *tsk,
270                                 const nodemask_t *new,
271                                 enum mpol_rebind_step step)
272 {
273 }
274
275 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
276 {
277 }
278
279 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
280 {
281 }
282
283 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
284                                 unsigned long addr, gfp_t gfp_flags,
285                                 struct mempolicy **mpol, nodemask_t **nodemask)
286 {
287         *mpol = NULL;
288         *nodemask = NULL;
289         return node_zonelist(0, gfp_flags);
290 }
291
292 static inline bool init_nodemask_of_mempolicy(nodemask_t *m)
293 {
294         return false;
295 }
296
297 static inline bool mempolicy_nodemask_intersects(struct task_struct *tsk,
298                         const nodemask_t *mask)
299 {
300         return false;
301 }
302
303 static inline int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
304                                    const nodemask_t *to, int flags)
305 {
306         return 0;
307 }
308
309 static inline void check_highest_zone(int k)
310 {
311 }
312
313 #ifdef CONFIG_TMPFS
314 static inline int mpol_parse_str(char *str, struct mempolicy **mpol,
315                                 int no_context)
316 {
317         return 1;       /* error */
318 }
319 #endif
320
321 static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol,
322                                 int no_context)
323 {
324         return 0;
325 }
326
327 static inline int mpol_misplaced(struct page *page, struct vm_area_struct *vma,
328                                  unsigned long address)
329 {
330         return -1; /* no node preference */
331 }
332
333 #endif /* CONFIG_NUMA */
334 #endif