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 */
28 #include <linux/config.h>
29 #include <linux/mmzone.h>
30 #include <linux/slab.h>
31 #include <linux/rbtree.h>
32 #include <linux/spinlock.h>
33 #include <linux/nodemask.h>
35 struct vm_area_struct;
40 * Describe a memory policy.
42 * A mempolicy can be either associated with a process or with a VMA.
43 * For VMA related allocations the VMA policy is preferred, otherwise
44 * the process policy is used. Interrupts ignore the memory policy
45 * of the current process.
47 * Locking policy for interlave:
48 * In process context there is no locking because only the process accesses
49 * its own state. All vma manipulation is somewhat protected by a down_read on
53 * When policy is MPOL_BIND v.zonelist is kmalloc'ed and must be kfree'd.
54 * All other policies don't have any external state. mpol_free() handles this.
56 * Copying policy objects:
57 * For MPOL_BIND the zonelist must be always duplicated. mpol_clone() does this.
61 short policy; /* See MPOL_* above */
63 struct zonelist *zonelist; /* bind */
64 short preferred_node; /* preferred */
65 nodemask_t nodes; /* interleave */
66 /* undefined for default */
71 * Support for managing mempolicy data objects (clone, copy, destroy)
72 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
75 extern void __mpol_free(struct mempolicy *pol);
76 static inline void mpol_free(struct mempolicy *pol)
82 extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
83 static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
86 pol = __mpol_copy(pol);
90 #define vma_policy(vma) ((vma)->vm_policy)
91 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
93 static inline void mpol_get(struct mempolicy *pol)
96 atomic_inc(&pol->refcnt);
99 extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
100 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
104 return __mpol_equal(a, b);
106 #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
108 /* Could later add inheritance of the process policy here. */
110 #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
113 * Tree of shared policies for a shared memory region.
114 * Maintain the policies in a pseudo mm that contains vmas. The vmas
115 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
116 * bytes, so that we can work with shared memory segments bigger than
122 unsigned long start, end;
123 struct mempolicy *policy;
126 struct shared_policy {
131 static inline void mpol_shared_policy_init(struct shared_policy *info)
133 info->root = RB_ROOT;
134 spin_lock_init(&info->lock);
137 int mpol_set_shared_policy(struct shared_policy *info,
138 struct vm_area_struct *vma,
139 struct mempolicy *new);
140 void mpol_free_shared_policy(struct shared_policy *p);
141 struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
144 struct mempolicy *get_vma_policy(struct task_struct *task,
145 struct vm_area_struct *vma, unsigned long addr);
147 extern void numa_default_policy(void);
148 extern void numa_policy_init(void);
149 extern void numa_policy_rebind(const nodemask_t *old, const nodemask_t *new);
150 extern struct mempolicy default_policy;
151 extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
154 extern int policy_zone;
156 static inline void check_highest_zone(int k)
166 static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
170 #define vma_mpol_equal(a,b) 1
172 #define mpol_set_vma_default(vma) do {} while(0)
174 static inline void mpol_free(struct mempolicy *p)
178 static inline void mpol_get(struct mempolicy *pol)
182 static inline struct mempolicy *mpol_copy(struct mempolicy *old)
187 struct shared_policy {};
189 static inline int mpol_set_shared_policy(struct shared_policy *info,
190 struct vm_area_struct *vma,
191 struct mempolicy *new)
196 static inline void mpol_shared_policy_init(struct shared_policy *info)
200 static inline void mpol_free_shared_policy(struct shared_policy *p)
204 static inline struct mempolicy *
205 mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
210 #define vma_policy(vma) NULL
211 #define vma_set_policy(vma, pol) do {} while(0)
213 static inline void numa_policy_init(void)
217 static inline void numa_default_policy(void)
221 static inline void numa_policy_rebind(const nodemask_t *old,
222 const nodemask_t *new)
226 static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
229 return NODE_DATA(0)->node_zonelists + gfp_zone(GFP_HIGHUSER);
232 static inline void check_highest_zone(int k)
235 #endif /* CONFIG_NUMA */
236 #endif /* __KERNEL__ */