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 */
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 */
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;
42 * Describe a memory policy.
44 * A mempolicy can be either associated with a process or with a VMA.
45 * For VMA related allocations the VMA policy is preferred, otherwise
46 * the process policy is used. Interrupts ignore the memory policy
47 * of the current process.
49 * Locking policy for interlave:
50 * In process context there is no locking because only the process accesses
51 * its own state. All vma manipulation is somewhat protected by a down_read on
55 * When policy is MPOL_BIND v.zonelist is kmalloc'ed and must be kfree'd.
56 * All other policies don't have any external state. mpol_free() handles this.
58 * Copying policy objects:
59 * For MPOL_BIND the zonelist must be always duplicated. mpol_clone() does this.
63 short policy; /* See MPOL_* above */
65 struct zonelist *zonelist; /* bind */
66 short preferred_node; /* preferred */
67 nodemask_t nodes; /* interleave */
68 /* undefined for default */
70 nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
74 * Support for managing mempolicy data objects (clone, copy, destroy)
75 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
78 extern void __mpol_free(struct mempolicy *pol);
79 static inline void mpol_free(struct mempolicy *pol)
85 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
86 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
89 pol = __mpol_copy(pol);
93 #define vma_policy(vma) ((vma)->vm_policy)
94 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
96 static inline void mpol_get(struct mempolicy *pol)
99 atomic_inc(&pol->refcnt);
102 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
103 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
107 return __mpol_equal(a, b);
109 #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
111 /* Could later add inheritance of the process policy here. */
113 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
116 * Tree of shared policies for a shared memory region.
117 * Maintain the policies in a pseudo mm that contains vmas. The vmas
118 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
119 * bytes, so that we can work with shared memory segments bigger than
125 unsigned long start, end;
126 struct mempolicy *policy;
129 struct shared_policy {
134 void mpol_shared_policy_init(struct shared_policy *info, int policy,
136 int mpol_set_shared_policy(struct shared_policy *info,
137 struct vm_area_struct *vma,
138 struct mempolicy *new);
139 void mpol_free_shared_policy(struct shared_policy *p);
140 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
143 extern void numa_default_policy(void);
144 extern void numa_policy_init(void);
145 extern void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *new);
146 extern void mpol_rebind_task(struct task_struct *tsk,
147 const nodemask_t *new);
148 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
149 extern void mpol_fix_fork_child_flag(struct task_struct *p);
150 #define set_cpuset_being_rebound(x) (cpuset_being_rebound = (x))
153 #define current_cpuset_is_being_rebound() \
154 (cpuset_being_rebound == current->cpuset)
156 #define current_cpuset_is_being_rebound() 0
159 extern struct mempolicy default_policy;
160 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
162 extern unsigned slab_node(struct mempolicy *policy);
164 extern int policy_zone;
166 static inline void check_highest_zone(int k)
172 int do_migrate_pages(struct mm_struct *mm,
173 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
175 extern void *cpuset_being_rebound; /* Trigger mpol_copy vma rebind */
181 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
185 #define vma_mpol_equal(a,b) 1
187 #define mpol_set_vma_default(vma) do {} while(0)
189 static inline void mpol_free(struct mempolicy *p)
193 static inline void mpol_get(struct mempolicy *pol)
197 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
202 struct shared_policy {};
204 static inline int mpol_set_shared_policy(struct shared_policy *info,
205 struct vm_area_struct *vma,
206 struct mempolicy *new)
211 static inline void mpol_shared_policy_init(struct shared_policy *info,
212 int policy, nodemask_t *nodes)
216 static inline void mpol_free_shared_policy(struct shared_policy *p)
220 static inline struct mempolicy *
221 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
226 #define vma_policy(vma) NULL
227 #define vma_set_policy(vma, pol) do {} while(0)
229 static inline void numa_policy_init(void)
233 static inline void numa_default_policy(void)
237 static inline void mpol_rebind_policy(struct mempolicy *pol,
238 const nodemask_t *new)
242 static inline void mpol_rebind_task(struct task_struct *tsk,
243 const nodemask_t *new)
247 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
251 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
255 #define set_cpuset_being_rebound(x) do {} while (0)
257 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
260 return NODE_DATA(0)->node_zonelists + gfp_zone(GFP_HIGHUSER);
263 static inline int do_migrate_pages(struct mm_struct *mm,
264 const nodemask_t *from_nodes,
265 const nodemask_t *to_nodes, int flags)
270 static inline void check_highest_zone(int k)
273 #endif /* CONFIG_NUMA */
274 #endif /* __KERNEL__ */