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 */
53 #define MPOL_F_LOCAL (1 << 1) /* preferred local allocation */
57 #include <linux/mmzone.h>
58 #include <linux/slab.h>
59 #include <linux/rbtree.h>
60 #include <linux/spinlock.h>
61 #include <linux/nodemask.h>
68 * Describe a memory policy.
70 * A mempolicy can be either associated with a process or with a VMA.
71 * For VMA related allocations the VMA policy is preferred, otherwise
72 * the process policy is used. Interrupts ignore the memory policy
73 * of the current process.
75 * Locking policy for interlave:
76 * In process context there is no locking because only the process accesses
77 * its own state. All vma manipulation is somewhat protected by a down_read on
81 * Mempolicy objects are reference counted. A mempolicy will be freed when
82 * mpol_put() decrements the reference count to zero.
84 * Duplicating policy objects:
85 * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
86 * to the new storage. The reference count of the new object is initialized
87 * to 1, representing the caller of mpol_dup().
91 unsigned short mode
; /* See MPOL_* above */
92 unsigned short flags
; /* See set_mempolicy() MPOL_F_* above */
94 short preferred_node
; /* preferred */
95 nodemask_t nodes
; /* interleave/bind */
96 /* undefined for default */
99 nodemask_t cpuset_mems_allowed
; /* relative to these nodes */
100 nodemask_t user_nodemask
; /* nodemask passed by user */
105 * Support for managing mempolicy data objects (clone, copy, destroy)
106 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
109 extern void __mpol_put(struct mempolicy
*pol
);
110 static inline void mpol_put(struct mempolicy
*pol
)
117 * Does mempolicy pol need explicit unref after use?
118 * Currently only needed for shared policies.
120 static inline int mpol_needs_cond_ref(struct mempolicy
*pol
)
122 return (pol
&& (pol
->flags
& MPOL_F_SHARED
));
125 static inline void mpol_cond_put(struct mempolicy
*pol
)
127 if (mpol_needs_cond_ref(pol
))
131 extern struct mempolicy
*__mpol_cond_copy(struct mempolicy
*tompol
,
132 struct mempolicy
*frompol
);
133 static inline struct mempolicy
*mpol_cond_copy(struct mempolicy
*tompol
,
134 struct mempolicy
*frompol
)
138 return __mpol_cond_copy(tompol
, frompol
);
141 extern struct mempolicy
*__mpol_dup(struct mempolicy
*pol
);
142 static inline struct mempolicy
*mpol_dup(struct mempolicy
*pol
)
145 pol
= __mpol_dup(pol
);
149 #define vma_policy(vma) ((vma)->vm_policy)
150 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
152 static inline void mpol_get(struct mempolicy
*pol
)
155 atomic_inc(&pol
->refcnt
);
158 extern int __mpol_equal(struct mempolicy
*a
, struct mempolicy
*b
);
159 static inline int mpol_equal(struct mempolicy
*a
, struct mempolicy
*b
)
163 return __mpol_equal(a
, b
);
167 * Tree of shared policies for a shared memory region.
168 * Maintain the policies in a pseudo mm that contains vmas. The vmas
169 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
170 * bytes, so that we can work with shared memory segments bigger than
176 unsigned long start
, end
;
177 struct mempolicy
*policy
;
180 struct shared_policy
{
185 void mpol_shared_policy_init(struct shared_policy
*info
, unsigned short mode
,
186 unsigned short flags
, nodemask_t
*nodes
);
187 int mpol_set_shared_policy(struct shared_policy
*info
,
188 struct vm_area_struct
*vma
,
189 struct mempolicy
*new);
190 void mpol_free_shared_policy(struct shared_policy
*p
);
191 struct mempolicy
*mpol_shared_policy_lookup(struct shared_policy
*sp
,
194 extern void numa_default_policy(void);
195 extern void numa_policy_init(void);
196 extern void mpol_rebind_task(struct task_struct
*tsk
,
197 const nodemask_t
*new);
198 extern void mpol_rebind_mm(struct mm_struct
*mm
, nodemask_t
*new);
199 extern void mpol_fix_fork_child_flag(struct task_struct
*p
);
201 extern struct zonelist
*huge_zonelist(struct vm_area_struct
*vma
,
202 unsigned long addr
, gfp_t gfp_flags
,
203 struct mempolicy
**mpol
, nodemask_t
**nodemask
);
204 extern unsigned slab_node(struct mempolicy
*policy
);
206 extern enum zone_type policy_zone
;
208 static inline void check_highest_zone(enum zone_type k
)
210 if (k
> policy_zone
&& k
!= ZONE_MOVABLE
)
214 int do_migrate_pages(struct mm_struct
*mm
,
215 const nodemask_t
*from_nodes
, const nodemask_t
*to_nodes
, int flags
);
219 extern int mpol_parse_str(char *str
, unsigned short *mode
,
220 unsigned short *mode_flags
, nodemask_t
*policy_nodes
);
222 extern int mpol_to_str(char *buffer
, int maxlen
, struct mempolicy
*pol
);
228 static inline int mpol_equal(struct mempolicy
*a
, struct mempolicy
*b
)
233 static inline void mpol_put(struct mempolicy
*p
)
237 static inline void mpol_cond_put(struct mempolicy
*pol
)
241 static inline struct mempolicy
*mpol_cond_copy(struct mempolicy
*to
,
242 struct mempolicy
*from
)
247 static inline void mpol_get(struct mempolicy
*pol
)
251 static inline struct mempolicy
*mpol_dup(struct mempolicy
*old
)
256 struct shared_policy
{};
258 static inline int mpol_set_shared_policy(struct shared_policy
*info
,
259 struct vm_area_struct
*vma
,
260 struct mempolicy
*new)
265 static inline void mpol_shared_policy_init(struct shared_policy
*info
,
266 unsigned short mode
, unsigned short flags
, nodemask_t
*nodes
)
270 static inline void mpol_free_shared_policy(struct shared_policy
*p
)
274 static inline struct mempolicy
*
275 mpol_shared_policy_lookup(struct shared_policy
*sp
, unsigned long idx
)
280 #define vma_policy(vma) NULL
281 #define vma_set_policy(vma, pol) do {} while(0)
283 static inline void numa_policy_init(void)
287 static inline void numa_default_policy(void)
291 static inline void mpol_rebind_task(struct task_struct
*tsk
,
292 const nodemask_t
*new)
296 static inline void mpol_rebind_mm(struct mm_struct
*mm
, nodemask_t
*new)
300 static inline void mpol_fix_fork_child_flag(struct task_struct
*p
)
304 static inline struct zonelist
*huge_zonelist(struct vm_area_struct
*vma
,
305 unsigned long addr
, gfp_t gfp_flags
,
306 struct mempolicy
**mpol
, nodemask_t
**nodemask
)
310 return node_zonelist(0, gfp_flags
);
313 static inline int do_migrate_pages(struct mm_struct
*mm
,
314 const nodemask_t
*from_nodes
,
315 const nodemask_t
*to_nodes
, int flags
)
320 static inline void check_highest_zone(int k
)
325 static inline int mpol_parse_str(char *value
, unsigned short *policy
,
326 unsigned short flags
, nodemask_t
*policy_nodes
)
331 static inline int mpol_to_str(char *buffer
, int maxlen
, struct mempolicy
*pol
)
337 #endif /* CONFIG_NUMA */
338 #endif /* __KERNEL__ */