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 * 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.
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 */
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 */
49 #include <linux/mmzone.h>
50 #include <linux/slab.h>
51 #include <linux/rbtree.h>
52 #include <linux/spinlock.h>
53 #include <linux/nodemask.h>
55 struct vm_area_struct;
61 * Describe a memory policy.
63 * A mempolicy can be either associated with a process or with a VMA.
64 * For VMA related allocations the VMA policy is preferred, otherwise
65 * the process policy is used. Interrupts ignore the memory policy
66 * of the current process.
68 * Locking policy for interlave:
69 * In process context there is no locking because only the process accesses
70 * its own state. All vma manipulation is somewhat protected by a down_read on
74 * Mempolicy objects are reference counted. A mempolicy will be freed when
75 * mpol_free() decrements the reference count to zero.
77 * Copying policy objects:
78 * mpol_copy() allocates a new mempolicy and copies the specified mempolicy
79 * to the new storage. The reference count of the new object is initialized
80 * to 1, representing the caller of mpol_copy().
84 unsigned short policy; /* See MPOL_* above */
85 unsigned short flags; /* See set_mempolicy() MPOL_F_* above */
87 short preferred_node; /* preferred */
88 nodemask_t nodes; /* interleave/bind */
89 /* undefined for default */
92 nodemask_t cpuset_mems_allowed; /* relative to these nodes */
93 nodemask_t user_nodemask; /* nodemask passed by user */
98 * Support for managing mempolicy data objects (clone, copy, destroy)
99 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
102 extern void __mpol_free(struct mempolicy *pol);
103 static inline void mpol_free(struct mempolicy *pol)
109 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
110 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
113 pol = __mpol_copy(pol);
117 #define vma_policy(vma) ((vma)->vm_policy)
118 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
120 static inline void mpol_get(struct mempolicy *pol)
123 atomic_inc(&pol->refcnt);
126 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
127 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
131 return __mpol_equal(a, b);
134 /* Could later add inheritance of the process policy here. */
136 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
139 * Tree of shared policies for a shared memory region.
140 * Maintain the policies in a pseudo mm that contains vmas. The vmas
141 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
142 * bytes, so that we can work with shared memory segments bigger than
148 unsigned long start, end;
149 struct mempolicy *policy;
152 struct shared_policy {
157 void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
158 unsigned short flags, nodemask_t *nodes);
159 int mpol_set_shared_policy(struct shared_policy *info,
160 struct vm_area_struct *vma,
161 struct mempolicy *new);
162 void mpol_free_shared_policy(struct shared_policy *p);
163 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
166 extern void numa_default_policy(void);
167 extern void numa_policy_init(void);
168 extern void mpol_rebind_task(struct task_struct *tsk,
169 const nodemask_t *new);
170 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
171 extern void mpol_fix_fork_child_flag(struct task_struct *p);
173 extern struct mempolicy default_policy;
174 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
175 unsigned long addr, gfp_t gfp_flags,
176 struct mempolicy **mpol, nodemask_t **nodemask);
177 extern unsigned slab_node(struct mempolicy *policy);
179 extern enum zone_type policy_zone;
181 static inline void check_highest_zone(enum zone_type k)
183 if (k > policy_zone && k != ZONE_MOVABLE)
187 int do_migrate_pages(struct mm_struct *mm,
188 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
194 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
199 #define mpol_set_vma_default(vma) do {} while(0)
201 static inline void mpol_free(struct mempolicy *p)
205 static inline void mpol_get(struct mempolicy *pol)
209 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
214 struct shared_policy {};
216 static inline int mpol_set_shared_policy(struct shared_policy *info,
217 struct vm_area_struct *vma,
218 struct mempolicy *new)
223 static inline void mpol_shared_policy_init(struct shared_policy *info,
224 unsigned short policy, unsigned short flags, nodemask_t *nodes)
228 static inline void mpol_free_shared_policy(struct shared_policy *p)
232 static inline struct mempolicy *
233 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
238 #define vma_policy(vma) NULL
239 #define vma_set_policy(vma, pol) do {} while(0)
241 static inline void numa_policy_init(void)
245 static inline void numa_default_policy(void)
249 static inline void mpol_rebind_task(struct task_struct *tsk,
250 const nodemask_t *new)
254 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
258 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
262 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
263 unsigned long addr, gfp_t gfp_flags,
264 struct mempolicy **mpol, nodemask_t **nodemask)
268 return node_zonelist(0, gfp_flags);
271 static inline int do_migrate_pages(struct mm_struct *mm,
272 const nodemask_t *from_nodes,
273 const nodemask_t *to_nodes, int flags)
278 static inline void check_highest_zone(int k)
281 #endif /* CONFIG_NUMA */
282 #endif /* __KERNEL__ */