Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_MEMPOLICY_H |
| 2 | #define _LINUX_MEMPOLICY_H 1 |
| 3 | |
| 4 | #include <linux/errno.h> |
| 5 | |
| 6 | /* |
| 7 | * NUMA memory policies for Linux. |
| 8 | * Copyright 2003,2004 Andi Kleen SuSE Labs |
| 9 | */ |
| 10 | |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 11 | /* |
| 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. |
| 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* Policies */ |
David Rientjes | a3b51e0 | 2008-04-28 02:12:23 -0700 | [diff] [blame] | 18 | enum { |
| 19 | MPOL_DEFAULT, |
| 20 | MPOL_PREFERRED, |
| 21 | MPOL_BIND, |
| 22 | MPOL_INTERLEAVE, |
| 23 | MPOL_MAX, /* always last member of enum */ |
| 24 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 26 | /* Flags for set_mempolicy */ |
David Rientjes | f5b087b | 2008-04-28 02:12:27 -0700 | [diff] [blame^] | 27 | #define MPOL_F_STATIC_NODES (1 << 15) |
| 28 | |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 29 | /* |
| 30 | * MPOL_MODE_FLAGS is the union of all possible optional mode flags passed to |
| 31 | * either set_mempolicy() or mbind(). |
| 32 | */ |
David Rientjes | f5b087b | 2008-04-28 02:12:27 -0700 | [diff] [blame^] | 33 | #define MPOL_MODE_FLAGS (MPOL_F_STATIC_NODES) |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 34 | |
| 35 | /* Flags for get_mempolicy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */ |
| 37 | #define MPOL_F_ADDR (1<<1) /* look up vma using address */ |
Lee Schermerhorn | 754af6f | 2007-10-16 01:24:51 -0700 | [diff] [blame] | 38 | #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* Flags for mbind */ |
| 41 | #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */ |
Christoph Lameter | dc9aa5b | 2006-01-08 01:00:50 -0800 | [diff] [blame] | 42 | #define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */ |
| 43 | #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */ |
| 44 | #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #ifdef __KERNEL__ |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/mmzone.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/slab.h> |
| 50 | #include <linux/rbtree.h> |
| 51 | #include <linux/spinlock.h> |
Andi Kleen | dfcd3c0 | 2005-10-29 18:15:48 -0700 | [diff] [blame] | 52 | #include <linux/nodemask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | struct vm_area_struct; |
Ralf Baechle | 45b35a5 | 2006-06-08 00:43:41 -0700 | [diff] [blame] | 55 | struct mm_struct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #ifdef CONFIG_NUMA |
| 58 | |
| 59 | /* |
| 60 | * Describe a memory policy. |
| 61 | * |
| 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. |
| 66 | * |
| 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 |
Hugh Dickins | b8072f0 | 2005-10-29 18:16:41 -0700 | [diff] [blame] | 70 | * mmap_sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | * |
| 72 | * Freeing policy: |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 73 | * Mempolicy objects are reference counted. A mempolicy will be freed when |
| 74 | * mpol_free() decrements the reference count to zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * |
| 76 | * Copying policy objects: |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 77 | * mpol_copy() 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_copy(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | */ |
| 81 | struct mempolicy { |
| 82 | atomic_t refcnt; |
David Rientjes | a3b51e0 | 2008-04-28 02:12:23 -0700 | [diff] [blame] | 83 | unsigned short policy; /* See MPOL_* above */ |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 84 | unsigned short flags; /* See set_mempolicy() MPOL_F_* above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | union { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | short preferred_node; /* preferred */ |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 87 | nodemask_t nodes; /* interleave/bind */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* undefined for default */ |
| 89 | } v; |
David Rientjes | f5b087b | 2008-04-28 02:12:27 -0700 | [diff] [blame^] | 90 | union { |
| 91 | nodemask_t cpuset_mems_allowed; /* relative to these nodes */ |
| 92 | nodemask_t user_nodemask; /* nodemask passed by user */ |
| 93 | } w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | /* |
| 97 | * Support for managing mempolicy data objects (clone, copy, destroy) |
| 98 | * The default fast path of a NULL MPOL_DEFAULT policy is always inlined. |
| 99 | */ |
| 100 | |
| 101 | extern void __mpol_free(struct mempolicy *pol); |
| 102 | static inline void mpol_free(struct mempolicy *pol) |
| 103 | { |
| 104 | if (pol) |
| 105 | __mpol_free(pol); |
| 106 | } |
| 107 | |
| 108 | extern struct mempolicy *__mpol_copy(struct mempolicy *pol); |
| 109 | static inline struct mempolicy *mpol_copy(struct mempolicy *pol) |
| 110 | { |
| 111 | if (pol) |
| 112 | pol = __mpol_copy(pol); |
| 113 | return pol; |
| 114 | } |
| 115 | |
| 116 | #define vma_policy(vma) ((vma)->vm_policy) |
| 117 | #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol)) |
| 118 | |
| 119 | static inline void mpol_get(struct mempolicy *pol) |
| 120 | { |
| 121 | if (pol) |
| 122 | atomic_inc(&pol->refcnt); |
| 123 | } |
| 124 | |
| 125 | extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b); |
| 126 | static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b) |
| 127 | { |
| 128 | if (a == b) |
| 129 | return 1; |
| 130 | return __mpol_equal(a, b); |
| 131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* Could later add inheritance of the process policy here. */ |
| 134 | |
| 135 | #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL) |
| 136 | |
| 137 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | * Tree of shared policies for a shared memory region. |
| 139 | * Maintain the policies in a pseudo mm that contains vmas. The vmas |
| 140 | * carry the policy. As a special twist the pseudo mm is indexed in pages, not |
| 141 | * bytes, so that we can work with shared memory segments bigger than |
| 142 | * unsigned long. |
| 143 | */ |
| 144 | |
| 145 | struct sp_node { |
| 146 | struct rb_node nd; |
| 147 | unsigned long start, end; |
| 148 | struct mempolicy *policy; |
| 149 | }; |
| 150 | |
| 151 | struct shared_policy { |
| 152 | struct rb_root root; |
| 153 | spinlock_t lock; |
| 154 | }; |
| 155 | |
David Rientjes | a3b51e0 | 2008-04-28 02:12:23 -0700 | [diff] [blame] | 156 | void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy, |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 157 | unsigned short flags, nodemask_t *nodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | int mpol_set_shared_policy(struct shared_policy *info, |
| 159 | struct vm_area_struct *vma, |
| 160 | struct mempolicy *new); |
| 161 | void mpol_free_shared_policy(struct shared_policy *p); |
| 162 | struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp, |
| 163 | unsigned long idx); |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | extern void numa_default_policy(void); |
| 166 | extern void numa_policy_init(void); |
Paul Jackson | 74cb215 | 2006-01-08 01:01:56 -0800 | [diff] [blame] | 167 | extern void mpol_rebind_task(struct task_struct *tsk, |
| 168 | const nodemask_t *new); |
Paul Jackson | 4225399 | 2006-01-08 01:01:59 -0800 | [diff] [blame] | 169 | extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new); |
Paul Jackson | c61afb1 | 2006-03-24 03:16:08 -0800 | [diff] [blame] | 170 | extern void mpol_fix_fork_child_flag(struct task_struct *p); |
Paul Jackson | 4225399 | 2006-01-08 01:01:59 -0800 | [diff] [blame] | 171 | |
Andi Kleen | d42c699 | 2005-07-06 19:56:03 +0200 | [diff] [blame] | 172 | extern struct mempolicy default_policy; |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 173 | extern struct zonelist *huge_zonelist(struct vm_area_struct *vma, |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 174 | unsigned long addr, gfp_t gfp_flags, |
| 175 | struct mempolicy **mpol, nodemask_t **nodemask); |
Christoph Lameter | dc85da1 | 2006-01-18 17:42:36 -0800 | [diff] [blame] | 176 | extern unsigned slab_node(struct mempolicy *policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Christoph Lameter | 2f6726e | 2006-09-25 23:31:18 -0700 | [diff] [blame] | 178 | extern enum zone_type policy_zone; |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 179 | |
Christoph Lameter | 2f6726e | 2006-09-25 23:31:18 -0700 | [diff] [blame] | 180 | static inline void check_highest_zone(enum zone_type k) |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 181 | { |
Mel Gorman | b377fd3 | 2007-08-22 14:02:05 -0700 | [diff] [blame] | 182 | if (k > policy_zone && k != ZONE_MOVABLE) |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 183 | policy_zone = k; |
| 184 | } |
| 185 | |
Christoph Lameter | 3974388 | 2006-01-08 01:00:51 -0800 | [diff] [blame] | 186 | int do_migrate_pages(struct mm_struct *mm, |
| 187 | const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags); |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | #else |
| 190 | |
| 191 | struct mempolicy {}; |
| 192 | |
| 193 | static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b) |
| 194 | { |
| 195 | return 1; |
| 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | #define mpol_set_vma_default(vma) do {} while(0) |
| 199 | |
| 200 | static inline void mpol_free(struct mempolicy *p) |
| 201 | { |
| 202 | } |
| 203 | |
| 204 | static inline void mpol_get(struct mempolicy *pol) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | static inline struct mempolicy *mpol_copy(struct mempolicy *old) |
| 209 | { |
| 210 | return NULL; |
| 211 | } |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | struct shared_policy {}; |
| 214 | |
| 215 | static inline int mpol_set_shared_policy(struct shared_policy *info, |
| 216 | struct vm_area_struct *vma, |
| 217 | struct mempolicy *new) |
| 218 | { |
| 219 | return -EINVAL; |
| 220 | } |
| 221 | |
Robin Holt | 7339ff8 | 2006-01-14 13:20:48 -0800 | [diff] [blame] | 222 | static inline void mpol_shared_policy_init(struct shared_policy *info, |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 223 | unsigned short policy, unsigned short flags, nodemask_t *nodes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | } |
| 226 | |
| 227 | static inline void mpol_free_shared_policy(struct shared_policy *p) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | static inline struct mempolicy * |
| 232 | mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx) |
| 233 | { |
| 234 | return NULL; |
| 235 | } |
| 236 | |
| 237 | #define vma_policy(vma) NULL |
| 238 | #define vma_set_policy(vma, pol) do {} while(0) |
| 239 | |
| 240 | static inline void numa_policy_init(void) |
| 241 | { |
| 242 | } |
| 243 | |
| 244 | static inline void numa_default_policy(void) |
| 245 | { |
| 246 | } |
| 247 | |
Paul Jackson | 74cb215 | 2006-01-08 01:01:56 -0800 | [diff] [blame] | 248 | static inline void mpol_rebind_task(struct task_struct *tsk, |
Paul Jackson | 68860ec | 2005-10-30 15:02:36 -0800 | [diff] [blame] | 249 | const nodemask_t *new) |
| 250 | { |
| 251 | } |
| 252 | |
Paul Jackson | 4225399 | 2006-01-08 01:01:59 -0800 | [diff] [blame] | 253 | static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new) |
| 254 | { |
| 255 | } |
| 256 | |
Paul Jackson | c61afb1 | 2006-03-24 03:16:08 -0800 | [diff] [blame] | 257 | static inline void mpol_fix_fork_child_flag(struct task_struct *p) |
| 258 | { |
| 259 | } |
| 260 | |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 261 | static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma, |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 262 | unsigned long addr, gfp_t gfp_flags, |
| 263 | struct mempolicy **mpol, nodemask_t **nodemask) |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 264 | { |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 265 | *mpol = NULL; |
| 266 | *nodemask = NULL; |
Mel Gorman | 0e88460 | 2008-04-28 02:12:14 -0700 | [diff] [blame] | 267 | return node_zonelist(0, gfp_flags); |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Paul Jackson | 45b07ef | 2006-01-08 01:00:56 -0800 | [diff] [blame] | 270 | static inline int do_migrate_pages(struct mm_struct *mm, |
| 271 | const nodemask_t *from_nodes, |
| 272 | const nodemask_t *to_nodes, int flags) |
| 273 | { |
| 274 | return 0; |
| 275 | } |
| 276 | |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 277 | static inline void check_highest_zone(int k) |
| 278 | { |
| 279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | #endif /* CONFIG_NUMA */ |
| 281 | #endif /* __KERNEL__ */ |
| 282 | |
| 283 | #endif |