Linux 2.6.33-rc2
[pohmelfs.git] / include / linux / mempolicy.h
blob1cc966cd3e5fff90b3cf893a2f91a6ec8747b0f7
1 #ifndef _LINUX_MEMPOLICY_H
2 #define _LINUX_MEMPOLICY_H 1
4 #include <linux/errno.h>
6 /*
7 * NUMA memory policies for Linux.
8 * Copyright 2003,2004 Andi Kleen SuSE Labs
9 */
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.
17 /* Policies */
18 enum {
19 MPOL_DEFAULT,
20 MPOL_PREFERRED,
21 MPOL_BIND,
22 MPOL_INTERLEAVE,
23 MPOL_MAX, /* always last member of enum */
26 /* Flags for set_mempolicy */
27 #define MPOL_F_STATIC_NODES (1 << 15)
28 #define MPOL_F_RELATIVE_NODES (1 << 14)
31 * MPOL_MODE_FLAGS is the union of all possible optional mode flags passed to
32 * either set_mempolicy() or mbind().
34 #define MPOL_MODE_FLAGS (MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES)
36 /* Flags for get_mempolicy */
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 */
39 #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
41 /* Flags for mbind */
42 #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
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 */
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.
52 #define MPOL_F_SHARED (1 << 0) /* identify shared policies */
53 #define MPOL_F_LOCAL (1 << 1) /* preferred local allocation */
55 #ifdef __KERNEL__
57 #include <linux/mmzone.h>
58 #include <linux/slab.h>
59 #include <linux/rbtree.h>
60 #include <linux/spinlock.h>
61 #include <linux/nodemask.h>
62 #include <linux/pagemap.h>
64 struct mm_struct;
66 #ifdef CONFIG_NUMA
69 * Describe a memory policy.
71 * A mempolicy can be either associated with a process or with a VMA.
72 * For VMA related allocations the VMA policy is preferred, otherwise
73 * the process policy is used. Interrupts ignore the memory policy
74 * of the current process.
76 * Locking policy for interlave:
77 * In process context there is no locking because only the process accesses
78 * its own state. All vma manipulation is somewhat protected by a down_read on
79 * mmap_sem.
81 * Freeing policy:
82 * Mempolicy objects are reference counted. A mempolicy will be freed when
83 * mpol_put() decrements the reference count to zero.
85 * Duplicating policy objects:
86 * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
87 * to the new storage. The reference count of the new object is initialized
88 * to 1, representing the caller of mpol_dup().
90 struct mempolicy {
91 atomic_t refcnt;
92 unsigned short mode; /* See MPOL_* above */
93 unsigned short flags; /* See set_mempolicy() MPOL_F_* above */
94 union {
95 short preferred_node; /* preferred */
96 nodemask_t nodes; /* interleave/bind */
97 /* undefined for default */
98 } v;
99 union {
100 nodemask_t cpuset_mems_allowed; /* relative to these nodes */
101 nodemask_t user_nodemask; /* nodemask passed by user */
102 } w;
106 * Support for managing mempolicy data objects (clone, copy, destroy)
107 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
110 extern void __mpol_put(struct mempolicy *pol);
111 static inline void mpol_put(struct mempolicy *pol)
113 if (pol)
114 __mpol_put(pol);
118 * Does mempolicy pol need explicit unref after use?
119 * Currently only needed for shared policies.
121 static inline int mpol_needs_cond_ref(struct mempolicy *pol)
123 return (pol && (pol->flags & MPOL_F_SHARED));
126 static inline void mpol_cond_put(struct mempolicy *pol)
128 if (mpol_needs_cond_ref(pol))
129 __mpol_put(pol);
132 extern struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol,
133 struct mempolicy *frompol);
134 static inline struct mempolicy *mpol_cond_copy(struct mempolicy *tompol,
135 struct mempolicy *frompol)
137 if (!frompol)
138 return frompol;
139 return __mpol_cond_copy(tompol, frompol);
142 extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
143 static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
145 if (pol)
146 pol = __mpol_dup(pol);
147 return pol;
150 #define vma_policy(vma) ((vma)->vm_policy)
151 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
153 static inline void mpol_get(struct mempolicy *pol)
155 if (pol)
156 atomic_inc(&pol->refcnt);
159 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
160 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
162 if (a == b)
163 return 1;
164 return __mpol_equal(a, b);
168 * Tree of shared policies for a shared memory region.
169 * Maintain the policies in a pseudo mm that contains vmas. The vmas
170 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
171 * bytes, so that we can work with shared memory segments bigger than
172 * unsigned long.
175 struct sp_node {
176 struct rb_node nd;
177 unsigned long start, end;
178 struct mempolicy *policy;
181 struct shared_policy {
182 struct rb_root root;
183 spinlock_t lock;
186 void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol);
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);
194 extern void numa_default_policy(void);
195 extern void numa_policy_init(void);
196 extern void mpol_rebind_task(struct task_struct *tsk,
197 const nodemask_t *new);
198 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
199 extern void mpol_fix_fork_child_flag(struct task_struct *p);
201 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
202 unsigned long addr, gfp_t gfp_flags,
203 struct mempolicy **mpol, nodemask_t **nodemask);
204 extern bool init_nodemask_of_mempolicy(nodemask_t *mask);
205 extern unsigned slab_node(struct mempolicy *policy);
207 extern enum zone_type policy_zone;
209 static inline void check_highest_zone(enum zone_type k)
211 if (k > policy_zone && k != ZONE_MOVABLE)
212 policy_zone = k;
215 int do_migrate_pages(struct mm_struct *mm,
216 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
219 #ifdef CONFIG_TMPFS
220 extern int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context);
222 extern int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol,
223 int no_context);
224 #endif
226 /* Check if a vma is migratable */
227 static inline int vma_migratable(struct vm_area_struct *vma)
229 if (vma->vm_flags & (VM_IO|VM_HUGETLB|VM_PFNMAP|VM_RESERVED))
230 return 0;
232 * Migration allocates pages in the highest zone. If we cannot
233 * do so then migration (at least from node to node) is not
234 * possible.
236 if (vma->vm_file &&
237 gfp_zone(mapping_gfp_mask(vma->vm_file->f_mapping))
238 < policy_zone)
239 return 0;
240 return 1;
243 #else
245 struct mempolicy {};
247 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
249 return 1;
252 static inline void mpol_put(struct mempolicy *p)
256 static inline void mpol_cond_put(struct mempolicy *pol)
260 static inline struct mempolicy *mpol_cond_copy(struct mempolicy *to,
261 struct mempolicy *from)
263 return from;
266 static inline void mpol_get(struct mempolicy *pol)
270 static inline struct mempolicy *mpol_dup(struct mempolicy *old)
272 return NULL;
275 struct shared_policy {};
277 static inline int mpol_set_shared_policy(struct shared_policy *info,
278 struct vm_area_struct *vma,
279 struct mempolicy *new)
281 return -EINVAL;
284 static inline void mpol_shared_policy_init(struct shared_policy *sp,
285 struct mempolicy *mpol)
289 static inline void mpol_free_shared_policy(struct shared_policy *p)
293 static inline struct mempolicy *
294 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
296 return NULL;
299 #define vma_policy(vma) NULL
300 #define vma_set_policy(vma, pol) do {} while(0)
302 static inline void numa_policy_init(void)
306 static inline void numa_default_policy(void)
310 static inline void mpol_rebind_task(struct task_struct *tsk,
311 const nodemask_t *new)
315 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
319 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
323 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
324 unsigned long addr, gfp_t gfp_flags,
325 struct mempolicy **mpol, nodemask_t **nodemask)
327 *mpol = NULL;
328 *nodemask = NULL;
329 return node_zonelist(0, gfp_flags);
332 static inline bool init_nodemask_of_mempolicy(nodemask_t *m) { return false; }
334 static inline int do_migrate_pages(struct mm_struct *mm,
335 const nodemask_t *from_nodes,
336 const nodemask_t *to_nodes, int flags)
338 return 0;
341 static inline void check_highest_zone(int k)
345 #ifdef CONFIG_TMPFS
346 static inline int mpol_parse_str(char *str, struct mempolicy **mpol,
347 int no_context)
349 return 1; /* error */
352 static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol,
353 int no_context)
355 return 0;
357 #endif
359 #endif /* CONFIG_NUMA */
360 #endif /* __KERNEL__ */
362 #endif