[PATCH] MSI-X: fix resume crash
[linux-2.6.22.y-op.git] / include / linux / mempolicy.h
blobdaabb3aa1ec6b96b5078f6236d2df87fbfe710f6
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 */
11 /* Policies */
12 #define MPOL_DEFAULT 0
13 #define MPOL_PREFERRED 1
14 #define MPOL_BIND 2
15 #define MPOL_INTERLEAVE 3
17 #define MPOL_MAX MPOL_INTERLEAVE
19 /* Flags for get_mem_policy */
20 #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
21 #define MPOL_F_ADDR (1<<1) /* look up vma using address */
23 /* Flags for mbind */
24 #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
25 #define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
26 #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
27 #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
29 #ifdef __KERNEL__
31 #include <linux/mmzone.h>
32 #include <linux/slab.h>
33 #include <linux/rbtree.h>
34 #include <linux/spinlock.h>
35 #include <linux/nodemask.h>
37 struct vm_area_struct;
38 struct mm_struct;
40 #ifdef CONFIG_NUMA
43 * Describe a memory policy.
45 * A mempolicy can be either associated with a process or with a VMA.
46 * For VMA related allocations the VMA policy is preferred, otherwise
47 * the process policy is used. Interrupts ignore the memory policy
48 * of the current process.
50 * Locking policy for interlave:
51 * In process context there is no locking because only the process accesses
52 * its own state. All vma manipulation is somewhat protected by a down_read on
53 * mmap_sem.
55 * Freeing policy:
56 * When policy is MPOL_BIND v.zonelist is kmalloc'ed and must be kfree'd.
57 * All other policies don't have any external state. mpol_free() handles this.
59 * Copying policy objects:
60 * For MPOL_BIND the zonelist must be always duplicated. mpol_clone() does this.
62 struct mempolicy {
63 atomic_t refcnt;
64 short policy; /* See MPOL_* above */
65 union {
66 struct zonelist *zonelist; /* bind */
67 short preferred_node; /* preferred */
68 nodemask_t nodes; /* interleave */
69 /* undefined for default */
70 } v;
71 nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
75 * Support for managing mempolicy data objects (clone, copy, destroy)
76 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
79 extern void __mpol_free(struct mempolicy *pol);
80 static inline void mpol_free(struct mempolicy *pol)
82 if (pol)
83 __mpol_free(pol);
86 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
87 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
89 if (pol)
90 pol = __mpol_copy(pol);
91 return pol;
94 #define vma_policy(vma) ((vma)->vm_policy)
95 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
97 static inline void mpol_get(struct mempolicy *pol)
99 if (pol)
100 atomic_inc(&pol->refcnt);
103 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
104 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
106 if (a == b)
107 return 1;
108 return __mpol_equal(a, b);
110 #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
112 /* Could later add inheritance of the process policy here. */
114 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
117 * Tree of shared policies for a shared memory region.
118 * Maintain the policies in a pseudo mm that contains vmas. The vmas
119 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
120 * bytes, so that we can work with shared memory segments bigger than
121 * unsigned long.
124 struct sp_node {
125 struct rb_node nd;
126 unsigned long start, end;
127 struct mempolicy *policy;
130 struct shared_policy {
131 struct rb_root root;
132 spinlock_t lock;
135 void mpol_shared_policy_init(struct shared_policy *info, int policy,
136 nodemask_t *nodes);
137 int mpol_set_shared_policy(struct shared_policy *info,
138 struct vm_area_struct *vma,
139 struct mempolicy *new);
140 void mpol_free_shared_policy(struct shared_policy *p);
141 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
142 unsigned long idx);
144 extern void numa_default_policy(void);
145 extern void numa_policy_init(void);
146 extern void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *new);
147 extern void mpol_rebind_task(struct task_struct *tsk,
148 const nodemask_t *new);
149 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
150 extern void mpol_fix_fork_child_flag(struct task_struct *p);
151 #define set_cpuset_being_rebound(x) (cpuset_being_rebound = (x))
153 #ifdef CONFIG_CPUSETS
154 #define current_cpuset_is_being_rebound() \
155 (cpuset_being_rebound == current->cpuset)
156 #else
157 #define current_cpuset_is_being_rebound() 0
158 #endif
160 extern struct mempolicy default_policy;
161 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
162 unsigned long addr);
163 extern unsigned slab_node(struct mempolicy *policy);
165 extern enum zone_type policy_zone;
167 static inline void check_highest_zone(enum zone_type k)
169 if (k > policy_zone)
170 policy_zone = k;
173 int do_migrate_pages(struct mm_struct *mm,
174 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
176 extern void *cpuset_being_rebound; /* Trigger mpol_copy vma rebind */
178 #else
180 struct mempolicy {};
182 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
184 return 1;
186 #define vma_mpol_equal(a,b) 1
188 #define mpol_set_vma_default(vma) do {} while(0)
190 static inline void mpol_free(struct mempolicy *p)
194 static inline void mpol_get(struct mempolicy *pol)
198 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
200 return NULL;
203 struct shared_policy {};
205 static inline int mpol_set_shared_policy(struct shared_policy *info,
206 struct vm_area_struct *vma,
207 struct mempolicy *new)
209 return -EINVAL;
212 static inline void mpol_shared_policy_init(struct shared_policy *info,
213 int policy, nodemask_t *nodes)
217 static inline void mpol_free_shared_policy(struct shared_policy *p)
221 static inline struct mempolicy *
222 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
224 return NULL;
227 #define vma_policy(vma) NULL
228 #define vma_set_policy(vma, pol) do {} while(0)
230 static inline void numa_policy_init(void)
234 static inline void numa_default_policy(void)
238 static inline void mpol_rebind_policy(struct mempolicy *pol,
239 const nodemask_t *new)
243 static inline void mpol_rebind_task(struct task_struct *tsk,
244 const nodemask_t *new)
248 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
252 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
256 #define set_cpuset_being_rebound(x) do {} while (0)
258 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
259 unsigned long addr)
261 return NODE_DATA(0)->node_zonelists + gfp_zone(GFP_HIGHUSER);
264 static inline int do_migrate_pages(struct mm_struct *mm,
265 const nodemask_t *from_nodes,
266 const nodemask_t *to_nodes, int flags)
268 return 0;
271 static inline void check_highest_zone(int k)
274 #endif /* CONFIG_NUMA */
275 #endif /* __KERNEL__ */
277 #endif