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) |
David Rientjes | 4c50bc0 | 2008-04-28 02:12:30 -0700 | [diff] [blame] | 28 | #define MPOL_F_RELATIVE_NODES (1 << 14) |
David Rientjes | f5b087b | 2008-04-28 02:12:27 -0700 | [diff] [blame] | 29 | |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 30 | /* |
| 31 | * MPOL_MODE_FLAGS is the union of all possible optional mode flags passed to |
| 32 | * either set_mempolicy() or mbind(). |
| 33 | */ |
David Rientjes | 4c50bc0 | 2008-04-28 02:12:30 -0700 | [diff] [blame] | 34 | #define MPOL_MODE_FLAGS (MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES) |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 35 | |
| 36 | /* Flags for get_mempolicy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Lee Schermerhorn | 754af6f | 2007-10-16 01:24:51 -0700 | [diff] [blame] | 39 | #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* Flags for mbind */ |
| 42 | #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */ |
Christoph Lameter | dc9aa5b | 2006-01-08 01:00:50 -0800 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Lee Schermerhorn | aab0b10 | 2008-04-28 02:13:13 -0700 | [diff] [blame] | 47 | /* |
| 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. |
| 51 | */ |
| 52 | #define MPOL_F_SHARED (1 << 0) /* identify shared policies */ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #ifdef __KERNEL__ |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <linux/mmzone.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <linux/slab.h> |
| 58 | #include <linux/rbtree.h> |
| 59 | #include <linux/spinlock.h> |
Andi Kleen | dfcd3c0 | 2005-10-29 18:15:48 -0700 | [diff] [blame] | 60 | #include <linux/nodemask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Ralf Baechle | 45b35a5 | 2006-06-08 00:43:41 -0700 | [diff] [blame] | 62 | struct mm_struct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #ifdef CONFIG_NUMA |
| 65 | |
| 66 | /* |
| 67 | * Describe a memory policy. |
| 68 | * |
| 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. |
| 73 | * |
| 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 |
Hugh Dickins | b8072f0 | 2005-10-29 18:16:41 -0700 | [diff] [blame] | 77 | * mmap_sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * |
| 79 | * Freeing policy: |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 80 | * Mempolicy objects are reference counted. A mempolicy will be freed when |
Lee Schermerhorn | f0be3d3 | 2008-04-28 02:13:08 -0700 | [diff] [blame] | 81 | * mpol_put() decrements the reference count to zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * |
Lee Schermerhorn | 846a16b | 2008-04-28 02:13:09 -0700 | [diff] [blame] | 83 | * Duplicating policy objects: |
| 84 | * mpol_dup() allocates a new mempolicy and copies the specified mempolicy |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 85 | * to the new storage. The reference count of the new object is initialized |
Lee Schermerhorn | 846a16b | 2008-04-28 02:13:09 -0700 | [diff] [blame] | 86 | * to 1, representing the caller of mpol_dup(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | */ |
| 88 | struct mempolicy { |
| 89 | atomic_t refcnt; |
Lee Schermerhorn | 45c4745 | 2008-04-28 02:13:12 -0700 | [diff] [blame] | 90 | unsigned short mode; /* See MPOL_* above */ |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 91 | unsigned short flags; /* See set_mempolicy() MPOL_F_* above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | union { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | short preferred_node; /* preferred */ |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 94 | nodemask_t nodes; /* interleave/bind */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* undefined for default */ |
| 96 | } v; |
David Rientjes | f5b087b | 2008-04-28 02:12:27 -0700 | [diff] [blame] | 97 | union { |
| 98 | nodemask_t cpuset_mems_allowed; /* relative to these nodes */ |
| 99 | nodemask_t user_nodemask; /* nodemask passed by user */ |
| 100 | } w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /* |
| 104 | * Support for managing mempolicy data objects (clone, copy, destroy) |
| 105 | * The default fast path of a NULL MPOL_DEFAULT policy is always inlined. |
| 106 | */ |
| 107 | |
Lee Schermerhorn | f0be3d3 | 2008-04-28 02:13:08 -0700 | [diff] [blame] | 108 | extern void __mpol_put(struct mempolicy *pol); |
| 109 | static inline void mpol_put(struct mempolicy *pol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | if (pol) |
Lee Schermerhorn | f0be3d3 | 2008-04-28 02:13:08 -0700 | [diff] [blame] | 112 | __mpol_put(pol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Lee Schermerhorn | 52cd3b0 | 2008-04-28 02:13:16 -0700 | [diff] [blame^] | 115 | /* |
| 116 | * Does mempolicy pol need explicit unref after use? |
| 117 | * Currently only needed for shared policies. |
| 118 | */ |
| 119 | static inline int mpol_needs_cond_ref(struct mempolicy *pol) |
| 120 | { |
| 121 | return (pol && (pol->flags & MPOL_F_SHARED)); |
| 122 | } |
| 123 | |
| 124 | static inline void mpol_cond_put(struct mempolicy *pol) |
| 125 | { |
| 126 | if (mpol_needs_cond_ref(pol)) |
| 127 | __mpol_put(pol); |
| 128 | } |
| 129 | |
| 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) |
| 134 | { |
| 135 | if (!frompol) |
| 136 | return frompol; |
| 137 | return __mpol_cond_copy(tompol, frompol); |
| 138 | } |
| 139 | |
Lee Schermerhorn | 846a16b | 2008-04-28 02:13:09 -0700 | [diff] [blame] | 140 | extern struct mempolicy *__mpol_dup(struct mempolicy *pol); |
| 141 | static inline struct mempolicy *mpol_dup(struct mempolicy *pol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | if (pol) |
Lee Schermerhorn | 846a16b | 2008-04-28 02:13:09 -0700 | [diff] [blame] | 144 | pol = __mpol_dup(pol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | return pol; |
| 146 | } |
| 147 | |
| 148 | #define vma_policy(vma) ((vma)->vm_policy) |
| 149 | #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol)) |
| 150 | |
| 151 | static inline void mpol_get(struct mempolicy *pol) |
| 152 | { |
| 153 | if (pol) |
| 154 | atomic_inc(&pol->refcnt); |
| 155 | } |
| 156 | |
| 157 | extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b); |
| 158 | static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b) |
| 159 | { |
| 160 | if (a == b) |
| 161 | return 1; |
| 162 | return __mpol_equal(a, b); |
| 163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
| 170 | * unsigned long. |
| 171 | */ |
| 172 | |
| 173 | struct sp_node { |
| 174 | struct rb_node nd; |
| 175 | unsigned long start, end; |
| 176 | struct mempolicy *policy; |
| 177 | }; |
| 178 | |
| 179 | struct shared_policy { |
| 180 | struct rb_root root; |
| 181 | spinlock_t lock; |
| 182 | }; |
| 183 | |
Lee Schermerhorn | 45c4745 | 2008-04-28 02:13:12 -0700 | [diff] [blame] | 184 | void mpol_shared_policy_init(struct shared_policy *info, unsigned short mode, |
David Rientjes | 028fec4 | 2008-04-28 02:12:25 -0700 | [diff] [blame] | 185 | unsigned short flags, nodemask_t *nodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
| 191 | unsigned long idx); |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | extern void numa_default_policy(void); |
| 194 | extern void numa_policy_init(void); |
Paul Jackson | 74cb215 | 2006-01-08 01:01:56 -0800 | [diff] [blame] | 195 | extern void mpol_rebind_task(struct task_struct *tsk, |
| 196 | const nodemask_t *new); |
Paul Jackson | 4225399 | 2006-01-08 01:01:59 -0800 | [diff] [blame] | 197 | extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new); |
Paul Jackson | c61afb1 | 2006-03-24 03:16:08 -0800 | [diff] [blame] | 198 | extern void mpol_fix_fork_child_flag(struct task_struct *p); |
Paul Jackson | 4225399 | 2006-01-08 01:01:59 -0800 | [diff] [blame] | 199 | |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 200 | extern struct zonelist *huge_zonelist(struct vm_area_struct *vma, |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 201 | unsigned long addr, gfp_t gfp_flags, |
| 202 | struct mempolicy **mpol, nodemask_t **nodemask); |
Christoph Lameter | dc85da1 | 2006-01-18 17:42:36 -0800 | [diff] [blame] | 203 | extern unsigned slab_node(struct mempolicy *policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Christoph Lameter | 2f6726e | 2006-09-25 23:31:18 -0700 | [diff] [blame] | 205 | extern enum zone_type policy_zone; |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 206 | |
Christoph Lameter | 2f6726e | 2006-09-25 23:31:18 -0700 | [diff] [blame] | 207 | static inline void check_highest_zone(enum zone_type k) |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 208 | { |
Mel Gorman | b377fd3 | 2007-08-22 14:02:05 -0700 | [diff] [blame] | 209 | if (k > policy_zone && k != ZONE_MOVABLE) |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 210 | policy_zone = k; |
| 211 | } |
| 212 | |
Christoph Lameter | 3974388 | 2006-01-08 01:00:51 -0800 | [diff] [blame] | 213 | int do_migrate_pages(struct mm_struct *mm, |
| 214 | const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags); |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | #else |
| 217 | |
| 218 | struct mempolicy {}; |
| 219 | |
| 220 | static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b) |
| 221 | { |
| 222 | return 1; |
| 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Lee Schermerhorn | f0be3d3 | 2008-04-28 02:13:08 -0700 | [diff] [blame] | 225 | static inline void mpol_put(struct mempolicy *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | } |
| 228 | |
Lee Schermerhorn | 52cd3b0 | 2008-04-28 02:13:16 -0700 | [diff] [blame^] | 229 | static inline void mpol_cond_put(struct mempolicy *pol) |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | static inline struct mempolicy *mpol_cond_copy(struct mempolicy *to, |
| 234 | struct mempolicy *from) |
| 235 | { |
| 236 | return from; |
| 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | static inline void mpol_get(struct mempolicy *pol) |
| 240 | { |
| 241 | } |
| 242 | |
Lee Schermerhorn | 846a16b | 2008-04-28 02:13:09 -0700 | [diff] [blame] | 243 | static inline struct mempolicy *mpol_dup(struct mempolicy *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | return NULL; |
| 246 | } |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | struct shared_policy {}; |
| 249 | |
| 250 | static inline int mpol_set_shared_policy(struct shared_policy *info, |
| 251 | struct vm_area_struct *vma, |
| 252 | struct mempolicy *new) |
| 253 | { |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | |
Robin Holt | 7339ff8 | 2006-01-14 13:20:48 -0800 | [diff] [blame] | 257 | static inline void mpol_shared_policy_init(struct shared_policy *info, |
Lee Schermerhorn | 45c4745 | 2008-04-28 02:13:12 -0700 | [diff] [blame] | 258 | unsigned short mode, unsigned short flags, nodemask_t *nodes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | } |
| 261 | |
| 262 | static inline void mpol_free_shared_policy(struct shared_policy *p) |
| 263 | { |
| 264 | } |
| 265 | |
| 266 | static inline struct mempolicy * |
| 267 | mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx) |
| 268 | { |
| 269 | return NULL; |
| 270 | } |
| 271 | |
| 272 | #define vma_policy(vma) NULL |
| 273 | #define vma_set_policy(vma, pol) do {} while(0) |
| 274 | |
| 275 | static inline void numa_policy_init(void) |
| 276 | { |
| 277 | } |
| 278 | |
| 279 | static inline void numa_default_policy(void) |
| 280 | { |
| 281 | } |
| 282 | |
Paul Jackson | 74cb215 | 2006-01-08 01:01:56 -0800 | [diff] [blame] | 283 | static inline void mpol_rebind_task(struct task_struct *tsk, |
Paul Jackson | 68860ec | 2005-10-30 15:02:36 -0800 | [diff] [blame] | 284 | const nodemask_t *new) |
| 285 | { |
| 286 | } |
| 287 | |
Paul Jackson | 4225399 | 2006-01-08 01:01:59 -0800 | [diff] [blame] | 288 | static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new) |
| 289 | { |
| 290 | } |
| 291 | |
Paul Jackson | c61afb1 | 2006-03-24 03:16:08 -0800 | [diff] [blame] | 292 | static inline void mpol_fix_fork_child_flag(struct task_struct *p) |
| 293 | { |
| 294 | } |
| 295 | |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 296 | static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma, |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 297 | unsigned long addr, gfp_t gfp_flags, |
| 298 | struct mempolicy **mpol, nodemask_t **nodemask) |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 299 | { |
Mel Gorman | 19770b3 | 2008-04-28 02:12:18 -0700 | [diff] [blame] | 300 | *mpol = NULL; |
| 301 | *nodemask = NULL; |
Mel Gorman | 0e88460 | 2008-04-28 02:12:14 -0700 | [diff] [blame] | 302 | return node_zonelist(0, gfp_flags); |
Christoph Lameter | 5da7ca8 | 2006-01-06 00:10:46 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Paul Jackson | 45b07ef | 2006-01-08 01:00:56 -0800 | [diff] [blame] | 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) |
| 308 | { |
| 309 | return 0; |
| 310 | } |
| 311 | |
Christoph Lameter | 4be38e3 | 2006-01-06 00:11:17 -0800 | [diff] [blame] | 312 | static inline void check_highest_zone(int k) |
| 313 | { |
| 314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | #endif /* CONFIG_NUMA */ |
| 316 | #endif /* __KERNEL__ */ |
| 317 | |
| 318 | #endif |