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>
60 * Describe a memory policy.
62 * A mempolicy can be either associated with a process or with a VMA.
63 * For VMA related allocations the VMA policy is preferred, otherwise
64 * the process policy is used. Interrupts ignore the memory policy
65 * of the current process.
67 * Locking policy for interlave:
68 * In process context there is no locking because only the process accesses
69 * its own state. All vma manipulation is somewhat protected by a down_read on
73 * Mempolicy objects are reference counted. A mempolicy will be freed when
74 * mpol_put() decrements the reference count to zero.
76 * Duplicating policy objects:
77 * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
78 * to the new storage. The reference count of the new object is initialized
79 * to 1, representing the caller of mpol_dup().
83 unsigned short mode; /* See MPOL_* above */
84 unsigned short flags; /* See set_mempolicy() MPOL_F_* above */
86 short preferred_node; /* preferred */
87 nodemask_t nodes; /* interleave/bind */
88 /* undefined for default */
91 nodemask_t cpuset_mems_allowed; /* relative to these nodes */
92 nodemask_t user_nodemask; /* nodemask passed by user */
97 * Support for managing mempolicy data objects (clone, copy, destroy)
98 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
101 extern void __mpol_put(struct mempolicy *pol);
102 static inline void mpol_put(struct mempolicy *pol)
108 extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
109 static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
112 pol = __mpol_dup(pol);
116 #define vma_policy(vma) ((vma)->vm_policy)
117 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
119 static inline void mpol_get(struct mempolicy *pol)
122 atomic_inc(&pol->refcnt);
125 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
126 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
130 return __mpol_equal(a, b);
134 * Tree of shared policies for a shared memory region.
135 * Maintain the policies in a pseudo mm that contains vmas. The vmas
136 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
137 * bytes, so that we can work with shared memory segments bigger than
143 unsigned long start, end;
144 struct mempolicy *policy;
147 struct shared_policy {
152 void mpol_shared_policy_init(struct shared_policy *info, unsigned short mode,
153 unsigned short flags, nodemask_t *nodes);
154 int mpol_set_shared_policy(struct shared_policy *info,
155 struct vm_area_struct *vma,
156 struct mempolicy *new);
157 void mpol_free_shared_policy(struct shared_policy *p);
158 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
161 extern void numa_default_policy(void);
162 extern void numa_policy_init(void);
163 extern void mpol_rebind_task(struct task_struct *tsk,
164 const nodemask_t *new);
165 extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
166 extern void mpol_fix_fork_child_flag(struct task_struct *p);
168 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
169 unsigned long addr, gfp_t gfp_flags,
170 struct mempolicy **mpol, nodemask_t **nodemask);
171 extern unsigned slab_node(struct mempolicy *policy);
173 extern enum zone_type policy_zone;
175 static inline void check_highest_zone(enum zone_type k)
177 if (k > policy_zone && k != ZONE_MOVABLE)
181 int do_migrate_pages(struct mm_struct *mm,
182 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
188 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
193 static inline void mpol_put(struct mempolicy *p)
197 static inline void mpol_get(struct mempolicy *pol)
201 static inline struct mempolicy *mpol_dup(struct mempolicy *old)
206 struct shared_policy {};
208 static inline int mpol_set_shared_policy(struct shared_policy *info,
209 struct vm_area_struct *vma,
210 struct mempolicy *new)
215 static inline void mpol_shared_policy_init(struct shared_policy *info,
216 unsigned short mode, unsigned short flags, nodemask_t *nodes)
220 static inline void mpol_free_shared_policy(struct shared_policy *p)
224 static inline struct mempolicy *
225 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
230 #define vma_policy(vma) NULL
231 #define vma_set_policy(vma, pol) do {} while(0)
233 static inline void numa_policy_init(void)
237 static inline void numa_default_policy(void)
241 static inline void mpol_rebind_task(struct task_struct *tsk,
242 const nodemask_t *new)
246 static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
250 static inline void mpol_fix_fork_child_flag(struct task_struct *p)
254 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
255 unsigned long addr, gfp_t gfp_flags,
256 struct mempolicy **mpol, nodemask_t **nodemask)
260 return node_zonelist(0, gfp_flags);
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__ */