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
17 MPOL_MAX, /* always last member of enum */
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 */
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 */
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>
39 struct vm_area_struct;
45 * Describe a memory policy.
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.
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
58 * Mempolicy objects are reference counted. A mempolicy will be freed when
59 * mpol_free() decrements the reference count to zero.
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().
68 unsigned short policy; /* See MPOL_* above */
70 short preferred_node; /* preferred */
71 nodemask_t nodes; /* interleave/bind */
72 /* undefined for default */
74 nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
78 * Support for managing mempolicy data objects (clone, copy, destroy)
79 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
82 extern void __mpol_free(struct mempolicy *pol);
83 static inline void mpol_free(struct mempolicy *pol)
89 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
90 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
93 pol = __mpol_copy(pol);
97 #define vma_policy(vma) ((vma)->vm_policy)
98 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
100 static inline void mpol_get(struct mempolicy *pol)
103 atomic_inc(&pol->refcnt);
106 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
107 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
111 return __mpol_equal(a, b);
113 #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
115 /* Could later add inheritance of the process policy here. */
117 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
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
129 unsigned long start, end;
130 struct mempolicy *policy;
133 struct shared_policy {
138 void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
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,
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);
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);
160 extern enum zone_type policy_zone;
162 static inline void check_highest_zone(enum zone_type k)
164 if (k > policy_zone && k != ZONE_MOVABLE)
168 int do_migrate_pages(struct mm_struct *mm,
169 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
175 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
179 #define vma_mpol_equal(a,b) 1
181 #define mpol_set_vma_default(vma) do {} while(0)
183 static inline void mpol_free(struct mempolicy *p)
187 static inline void mpol_get(struct mempolicy *pol)
191 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
196 struct shared_policy {};
198 static inline int mpol_set_shared_policy(struct shared_policy *info,
199 struct vm_area_struct *vma,
200 struct mempolicy *new)
205 static inline void mpol_shared_policy_init(struct shared_policy *info,
206 unsigned short policy, nodemask_t *nodes)
210 static inline void mpol_free_shared_policy(struct shared_policy *p)
214 static inline struct mempolicy *
215 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
220 #define vma_policy(vma) NULL
221 #define vma_set_policy(vma, pol) do {} while(0)
223 static inline void numa_policy_init(void)
227 static inline void numa_default_policy(void)
231 static inline void mpol_rebind_task(struct task_struct *tsk,
232 const nodemask_t *new)
236 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
240 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
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)
250 return node_zonelist(0, gfp_flags);
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)
260 static inline void check_highest_zone(int k)
263 #endif /* CONFIG_NUMA */
264 #endif /* __KERNEL__ */