]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/mempolicy.h
389a06e8ee211cf4b745dd533d04be53402da62c
[linux-2.6-omap-h63xx.git] / include / linux / mempolicy.h
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
11 /* Policies */
12 enum {
13         MPOL_DEFAULT,
14         MPOL_PREFERRED,
15         MPOL_BIND,
16         MPOL_INTERLEAVE,
17         MPOL_MAX,       /* always last member of enum */
18 };
19
20 /* Flags for get_mem_policy */
21 #define MPOL_F_NODE     (1<<0)  /* return next IL mode instead of node mask */
22 #define MPOL_F_ADDR     (1<<1)  /* look up vma using address */
23 #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
24
25 /* Flags for mbind */
26 #define MPOL_MF_STRICT  (1<<0)  /* Verify existing pages in the mapping */
27 #define MPOL_MF_MOVE    (1<<1)  /* Move pages owned by this process to conform to mapping */
28 #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
29 #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
30
31 #ifdef __KERNEL__
32
33 #include <linux/mmzone.h>
34 #include <linux/slab.h>
35 #include <linux/rbtree.h>
36 #include <linux/spinlock.h>
37 #include <linux/nodemask.h>
38
39 struct vm_area_struct;
40 struct mm_struct;
41
42 #ifdef CONFIG_NUMA
43
44 /*
45  * Describe a memory policy.
46  *
47  * A mempolicy can be either associated with a process or with a VMA.
48  * For VMA related allocations the VMA policy is preferred, otherwise
49  * the process policy is used. Interrupts ignore the memory policy
50  * of the current process.
51  *
52  * Locking policy for interlave:
53  * In process context there is no locking because only the process accesses
54  * its own state. All vma manipulation is somewhat protected by a down_read on
55  * mmap_sem.
56  *
57  * Freeing policy:
58  * Mempolicy objects are reference counted.  A mempolicy will be freed when
59  * mpol_free() decrements the reference count to zero.
60  *
61  * Copying policy objects:
62  * mpol_copy() allocates a new mempolicy and copies the specified mempolicy
63  * to the new storage.  The reference count of the new object is initialized
64  * to 1, representing the caller of mpol_copy().
65  */
66 struct mempolicy {
67         atomic_t refcnt;
68         unsigned short policy;  /* See MPOL_* above */
69         union {
70                 short            preferred_node; /* preferred */
71                 nodemask_t       nodes;         /* interleave/bind */
72                 /* undefined for default */
73         } v;
74         nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
75 };
76
77 /*
78  * Support for managing mempolicy data objects (clone, copy, destroy)
79  * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
80  */
81
82 extern void __mpol_free(struct mempolicy *pol);
83 static inline void mpol_free(struct mempolicy *pol)
84 {
85         if (pol)
86                 __mpol_free(pol);
87 }
88
89 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
90 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
91 {
92         if (pol)
93                 pol = __mpol_copy(pol);
94         return pol;
95 }
96
97 #define vma_policy(vma) ((vma)->vm_policy)
98 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
99
100 static inline void mpol_get(struct mempolicy *pol)
101 {
102         if (pol)
103                 atomic_inc(&pol->refcnt);
104 }
105
106 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
107 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
108 {
109         if (a == b)
110                 return 1;
111         return __mpol_equal(a, b);
112 }
113 #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
114
115 /* Could later add inheritance of the process policy here. */
116
117 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
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         spinlock_t lock;
136 };
137
138 void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
139                                 nodemask_t *nodes);
140 int mpol_set_shared_policy(struct shared_policy *info,
141                                 struct vm_area_struct *vma,
142                                 struct mempolicy *new);
143 void mpol_free_shared_policy(struct shared_policy *p);
144 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
145                                             unsigned long idx);
146
147 extern void numa_default_policy(void);
148 extern void numa_policy_init(void);
149 extern void mpol_rebind_task(struct task_struct *tsk,
150                                         const nodemask_t *new);
151 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
152 extern void mpol_fix_fork_child_flag(struct task_struct *p);
153
154 extern struct mempolicy default_policy;
155 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
156                                 unsigned long addr, gfp_t gfp_flags,
157                                 struct mempolicy **mpol, nodemask_t **nodemask);
158 extern unsigned slab_node(struct mempolicy *policy);
159
160 extern enum zone_type policy_zone;
161
162 static inline void check_highest_zone(enum zone_type k)
163 {
164         if (k > policy_zone && k != ZONE_MOVABLE)
165                 policy_zone = k;
166 }
167
168 int do_migrate_pages(struct mm_struct *mm,
169         const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
170
171 #else
172
173 struct mempolicy {};
174
175 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
176 {
177         return 1;
178 }
179 #define vma_mpol_equal(a,b) 1
180
181 #define mpol_set_vma_default(vma) do {} while(0)
182
183 static inline void mpol_free(struct mempolicy *p)
184 {
185 }
186
187 static inline void mpol_get(struct mempolicy *pol)
188 {
189 }
190
191 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
192 {
193         return NULL;
194 }
195
196 struct shared_policy {};
197
198 static inline int mpol_set_shared_policy(struct shared_policy *info,
199                                         struct vm_area_struct *vma,
200                                         struct mempolicy *new)
201 {
202         return -EINVAL;
203 }
204
205 static inline void mpol_shared_policy_init(struct shared_policy *info,
206                                 unsigned short policy, nodemask_t *nodes)
207 {
208 }
209
210 static inline void mpol_free_shared_policy(struct shared_policy *p)
211 {
212 }
213
214 static inline struct mempolicy *
215 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
216 {
217         return NULL;
218 }
219
220 #define vma_policy(vma) NULL
221 #define vma_set_policy(vma, pol) do {} while(0)
222
223 static inline void numa_policy_init(void)
224 {
225 }
226
227 static inline void numa_default_policy(void)
228 {
229 }
230
231 static inline void mpol_rebind_task(struct task_struct *tsk,
232                                         const nodemask_t *new)
233 {
234 }
235
236 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
237 {
238 }
239
240 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
241 {
242 }
243
244 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
245                                 unsigned long addr, gfp_t gfp_flags,
246                                 struct mempolicy **mpol, nodemask_t **nodemask)
247 {
248         *mpol = NULL;
249         *nodemask = NULL;
250         return node_zonelist(0, gfp_flags);
251 }
252
253 static inline int do_migrate_pages(struct mm_struct *mm,
254                         const nodemask_t *from_nodes,
255                         const nodemask_t *to_nodes, int flags)
256 {
257         return 0;
258 }
259
260 static inline void check_highest_zone(int k)
261 {
262 }
263 #endif /* CONFIG_NUMA */
264 #endif /* __KERNEL__ */
265
266 #endif