1 #ifndef _LINUX_MEMPOLICY_H
2 #define _LINUX_MEMPOLICY_H 1
4 #include <linux/errno.h>
7 * NUMA memory policies for Linux.
8 * Copyright 2003,2004 Andi Kleen SuSE Labs
12 #define MPOL_DEFAULT 0
13 #define MPOL_PREFERRED 1
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 */
22 #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
25 #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
26 #define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
27 #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
28 #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
32 #include <linux/mmzone.h>
33 #include <linux/slab.h>
34 #include <linux/rbtree.h>
35 #include <linux/spinlock.h>
36 #include <linux/nodemask.h>
38 struct vm_area_struct;
44 * Describe a memory policy.
46 * A mempolicy can be either associated with a process or with a VMA.
47 * For VMA related allocations the VMA policy is preferred, otherwise
48 * the process policy is used. Interrupts ignore the memory policy
49 * of the current process.
51 * Locking policy for interlave:
52 * In process context there is no locking because only the process accesses
53 * its own state. All vma manipulation is somewhat protected by a down_read on
57 * Mempolicy objects are reference counted. A mempolicy will be freed when
58 * mpol_free() decrements the reference count to zero.
60 * Copying policy objects:
61 * mpol_copy() allocates a new mempolicy and copies the specified mempolicy
62 * to the new storage. The reference count of the new object is initialized
63 * to 1, representing the caller of mpol_copy().
67 short policy; /* See MPOL_* above */
69 short preferred_node; /* preferred */
70 nodemask_t nodes; /* interleave/bind */
71 /* undefined for default */
73 nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
77 * Support for managing mempolicy data objects (clone, copy, destroy)
78 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
81 extern void __mpol_free(struct mempolicy *pol);
82 static inline void mpol_free(struct mempolicy *pol)
88 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
89 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
92 pol = __mpol_copy(pol);
96 #define vma_policy(vma) ((vma)->vm_policy)
97 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
99 static inline void mpol_get(struct mempolicy *pol)
102 atomic_inc(&pol->refcnt);
105 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
106 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
110 return __mpol_equal(a, b);
112 #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
114 /* Could later add inheritance of the process policy here. */
116 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
119 * Tree of shared policies for a shared memory region.
120 * Maintain the policies in a pseudo mm that contains vmas. The vmas
121 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
122 * bytes, so that we can work with shared memory segments bigger than
128 unsigned long start, end;
129 struct mempolicy *policy;
132 struct shared_policy {
137 void mpol_shared_policy_init(struct shared_policy *info, int policy,
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,
146 extern void numa_default_policy(void);
147 extern void numa_policy_init(void);
148 extern void mpol_rebind_task(struct task_struct *tsk,
149 const nodemask_t *new);
150 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
151 extern void mpol_fix_fork_child_flag(struct task_struct *p);
153 extern struct mempolicy default_policy;
154 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
155 unsigned long addr, gfp_t gfp_flags,
156 struct mempolicy **mpol, nodemask_t **nodemask);
157 extern unsigned slab_node(struct mempolicy *policy);
159 extern enum zone_type policy_zone;
161 static inline void check_highest_zone(enum zone_type k)
163 if (k > policy_zone && k != ZONE_MOVABLE)
167 int do_migrate_pages(struct mm_struct *mm,
168 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
174 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
178 #define vma_mpol_equal(a,b) 1
180 #define mpol_set_vma_default(vma) do {} while(0)
182 static inline void mpol_free(struct mempolicy *p)
186 static inline void mpol_get(struct mempolicy *pol)
190 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
195 struct shared_policy {};
197 static inline int mpol_set_shared_policy(struct shared_policy *info,
198 struct vm_area_struct *vma,
199 struct mempolicy *new)
204 static inline void mpol_shared_policy_init(struct shared_policy *info,
205 int policy, nodemask_t *nodes)
209 static inline void mpol_free_shared_policy(struct shared_policy *p)
213 static inline struct mempolicy *
214 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
219 #define vma_policy(vma) NULL
220 #define vma_set_policy(vma, pol) do {} while(0)
222 static inline void numa_policy_init(void)
226 static inline void numa_default_policy(void)
230 static inline void mpol_rebind_task(struct task_struct *tsk,
231 const nodemask_t *new)
235 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
239 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
243 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
244 unsigned long addr, gfp_t gfp_flags,
245 struct mempolicy **mpol, nodemask_t **nodemask)
249 return node_zonelist(0, gfp_flags);
252 static inline int do_migrate_pages(struct mm_struct *mm,
253 const nodemask_t *from_nodes,
254 const nodemask_t *to_nodes, int flags)
259 static inline void check_highest_zone(int k)
262 #endif /* CONFIG_NUMA */
263 #endif /* __KERNEL__ */