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 */
48 * Internal flags that share the struct mempolicy flags word with
49 * "mode flags". These flags are allocated from bit 0 up, as they
50 * are never OR'ed into the mode in mempolicy API arguments.
52 #define MPOL_F_SHARED (1 << 0) /* identify shared policies */
56 #include <linux/mmzone.h>
57 #include <linux/slab.h>
58 #include <linux/rbtree.h>
59 #include <linux/spinlock.h>
60 #include <linux/nodemask.h>
67 * Describe a memory policy.
69 * A mempolicy can be either associated with a process or with a VMA.
70 * For VMA related allocations the VMA policy is preferred, otherwise
71 * the process policy is used. Interrupts ignore the memory policy
72 * of the current process.
74 * Locking policy for interlave:
75 * In process context there is no locking because only the process accesses
76 * its own state. All vma manipulation is somewhat protected by a down_read on
80 * Mempolicy objects are reference counted. A mempolicy will be freed when
81 * mpol_put() decrements the reference count to zero.
83 * Duplicating policy objects:
84 * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
85 * to the new storage. The reference count of the new object is initialized
86 * to 1, representing the caller of mpol_dup().
90 unsigned short mode
; /* See MPOL_* above */
91 unsigned short flags
; /* See set_mempolicy() MPOL_F_* above */
93 short preferred_node
; /* preferred */
94 nodemask_t nodes
; /* interleave/bind */
95 /* undefined for default */
98 nodemask_t cpuset_mems_allowed
; /* relative to these nodes */
99 nodemask_t user_nodemask
; /* nodemask passed by user */
104 * Support for managing mempolicy data objects (clone, copy, destroy)
105 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
108 extern void __mpol_put(struct mempolicy
*pol
);
109 static inline void mpol_put(struct mempolicy
*pol
)
116 * Does mempolicy pol need explicit unref after use?
117 * Currently only needed for shared policies.
119 static inline int mpol_needs_cond_ref(struct mempolicy
*pol
)
121 return (pol
&& (pol
->flags
& MPOL_F_SHARED
));
124 static inline void mpol_cond_put(struct mempolicy
*pol
)
126 if (mpol_needs_cond_ref(pol
))
130 extern struct mempolicy
*__mpol_cond_copy(struct mempolicy
*tompol
,
131 struct mempolicy
*frompol
);
132 static inline struct mempolicy
*mpol_cond_copy(struct mempolicy
*tompol
,
133 struct mempolicy
*frompol
)
137 return __mpol_cond_copy(tompol
, frompol
);
140 extern struct mempolicy
*__mpol_dup(struct mempolicy
*pol
);
141 static inline struct mempolicy
*mpol_dup(struct mempolicy
*pol
)
144 pol
= __mpol_dup(pol
);
148 #define vma_policy(vma) ((vma)->vm_policy)
149 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
151 static inline void mpol_get(struct mempolicy
*pol
)
154 atomic_inc(&pol
->refcnt
);
157 extern int __mpol_equal(struct mempolicy
*a
, struct mempolicy
*b
);
158 static inline int mpol_equal(struct mempolicy
*a
, struct mempolicy
*b
)
162 return __mpol_equal(a
, b
);
166 * Tree of shared policies for a shared memory region.
167 * Maintain the policies in a pseudo mm that contains vmas. The vmas
168 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
169 * bytes, so that we can work with shared memory segments bigger than
175 unsigned long start
, end
;
176 struct mempolicy
*policy
;
179 struct shared_policy
{
184 void mpol_shared_policy_init(struct shared_policy
*info
, unsigned short mode
,
185 unsigned short flags
, nodemask_t
*nodes
);
186 int mpol_set_shared_policy(struct shared_policy
*info
,
187 struct vm_area_struct
*vma
,
188 struct mempolicy
*new);
189 void mpol_free_shared_policy(struct shared_policy
*p
);
190 struct mempolicy
*mpol_shared_policy_lookup(struct shared_policy
*sp
,
193 extern void numa_default_policy(void);
194 extern void numa_policy_init(void);
195 extern void mpol_rebind_task(struct task_struct
*tsk
,
196 const nodemask_t
*new);
197 extern void mpol_rebind_mm(struct mm_struct
*mm
, nodemask_t
*new);
198 extern void mpol_fix_fork_child_flag(struct task_struct
*p
);
200 extern struct zonelist
*huge_zonelist(struct vm_area_struct
*vma
,
201 unsigned long addr
, gfp_t gfp_flags
,
202 struct mempolicy
**mpol
, nodemask_t
**nodemask
);
203 extern unsigned slab_node(struct mempolicy
*policy
);
205 extern enum zone_type policy_zone
;
207 static inline void check_highest_zone(enum zone_type k
)
209 if (k
> policy_zone
&& k
!= ZONE_MOVABLE
)
213 int do_migrate_pages(struct mm_struct
*mm
,
214 const nodemask_t
*from_nodes
, const nodemask_t
*to_nodes
, int flags
);
220 static inline int mpol_equal(struct mempolicy
*a
, struct mempolicy
*b
)
225 static inline void mpol_put(struct mempolicy
*p
)
229 static inline void mpol_cond_put(struct mempolicy
*pol
)
233 static inline struct mempolicy
*mpol_cond_copy(struct mempolicy
*to
,
234 struct mempolicy
*from
)
239 static inline void mpol_get(struct mempolicy
*pol
)
243 static inline struct mempolicy
*mpol_dup(struct mempolicy
*old
)
248 struct shared_policy
{};
250 static inline int mpol_set_shared_policy(struct shared_policy
*info
,
251 struct vm_area_struct
*vma
,
252 struct mempolicy
*new)
257 static inline void mpol_shared_policy_init(struct shared_policy
*info
,
258 unsigned short mode
, unsigned short flags
, nodemask_t
*nodes
)
262 static inline void mpol_free_shared_policy(struct shared_policy
*p
)
266 static inline struct mempolicy
*
267 mpol_shared_policy_lookup(struct shared_policy
*sp
, unsigned long idx
)
272 #define vma_policy(vma) NULL
273 #define vma_set_policy(vma, pol) do {} while(0)
275 static inline void numa_policy_init(void)
279 static inline void numa_default_policy(void)
283 static inline void mpol_rebind_task(struct task_struct
*tsk
,
284 const nodemask_t
*new)
288 static inline void mpol_rebind_mm(struct mm_struct
*mm
, nodemask_t
*new)
292 static inline void mpol_fix_fork_child_flag(struct task_struct
*p
)
296 static inline struct zonelist
*huge_zonelist(struct vm_area_struct
*vma
,
297 unsigned long addr
, gfp_t gfp_flags
,
298 struct mempolicy
**mpol
, nodemask_t
**nodemask
)
302 return node_zonelist(0, gfp_flags
);
305 static inline int do_migrate_pages(struct mm_struct
*mm
,
306 const nodemask_t
*from_nodes
,
307 const nodemask_t
*to_nodes
, int flags
)
312 static inline void check_highest_zone(int k
)
315 #endif /* CONFIG_NUMA */
316 #endif /* __KERNEL__ */