blob: b8b3da7a3315b1616d0c48429112663b57c8d660 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
11/* Policies */
12#define MPOL_DEFAULT 0
13#define MPOL_PREFERRED 1
14#define MPOL_BIND 2
15#define MPOL_INTERLEAVE 3
16
17#define MPOL_MAX MPOL_INTERLEAVE
18
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 */
Lee Schermerhorn754af6f2007-10-16 01:24:51 -070022#define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/* Flags for mbind */
25#define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
Christoph Lameterdc9aa5b2006-01-08 01:00:50 -080026#define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
27#define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
28#define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#ifdef __KERNEL__
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/mmzone.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/slab.h>
34#include <linux/rbtree.h>
35#include <linux/spinlock.h>
Andi Kleendfcd3c02005-10-29 18:15:48 -070036#include <linux/nodemask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38struct vm_area_struct;
Ralf Baechle45b35a52006-06-08 00:43:41 -070039struct mm_struct;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#ifdef CONFIG_NUMA
42
43/*
44 * Describe a memory policy.
45 *
46 * A mempolicy can be either associated with a process or with a VMA.
47 * For VMA related allocations the VMA policy is preferred, otherwise
48 * the process policy is used. Interrupts ignore the memory policy
49 * of the current process.
50 *
51 * Locking policy for interlave:
52 * In process context there is no locking because only the process accesses
53 * its own state. All vma manipulation is somewhat protected by a down_read on
Hugh Dickinsb8072f02005-10-29 18:16:41 -070054 * mmap_sem.
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 *
56 * Freeing policy:
Mel Gorman19770b32008-04-28 02:12:18 -070057 * Mempolicy objects are reference counted. A mempolicy will be freed when
58 * mpol_free() decrements the reference count to zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 *
60 * Copying policy objects:
Mel Gorman19770b32008-04-28 02:12:18 -070061 * mpol_copy() allocates a new mempolicy and copies the specified mempolicy
62 * to the new storage. The reference count of the new object is initialized
63 * to 1, representing the caller of mpol_copy().
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
65struct mempolicy {
66 atomic_t refcnt;
67 short policy; /* See MPOL_* above */
68 union {
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 short preferred_node; /* preferred */
Mel Gorman19770b32008-04-28 02:12:18 -070070 nodemask_t nodes; /* interleave/bind */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 /* undefined for default */
72 } v;
Paul Jackson74cb2152006-01-08 01:01:56 -080073 nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
76/*
77 * Support for managing mempolicy data objects (clone, copy, destroy)
78 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
79 */
80
81extern void __mpol_free(struct mempolicy *pol);
82static inline void mpol_free(struct mempolicy *pol)
83{
84 if (pol)
85 __mpol_free(pol);
86}
87
88extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
89static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
90{
91 if (pol)
92 pol = __mpol_copy(pol);
93 return pol;
94}
95
96#define vma_policy(vma) ((vma)->vm_policy)
97#define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
98
99static inline void mpol_get(struct mempolicy *pol)
100{
101 if (pol)
102 atomic_inc(&pol->refcnt);
103}
104
105extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
106static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
107{
108 if (a == b)
109 return 1;
110 return __mpol_equal(a, b);
111}
112#define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
113
114/* Could later add inheritance of the process policy here. */
115
116#define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
117
118/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 * Tree of shared policies for a shared memory region.
120 * Maintain the policies in a pseudo mm that contains vmas. The vmas
121 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
122 * bytes, so that we can work with shared memory segments bigger than
123 * unsigned long.
124 */
125
126struct sp_node {
127 struct rb_node nd;
128 unsigned long start, end;
129 struct mempolicy *policy;
130};
131
132struct shared_policy {
133 struct rb_root root;
134 spinlock_t lock;
135};
136
Robin Holt7339ff82006-01-14 13:20:48 -0800137void mpol_shared_policy_init(struct shared_policy *info, int policy,
138 nodemask_t *nodes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139int mpol_set_shared_policy(struct shared_policy *info,
140 struct vm_area_struct *vma,
141 struct mempolicy *new);
142void mpol_free_shared_policy(struct shared_policy *p);
143struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
144 unsigned long idx);
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146extern void numa_default_policy(void);
147extern void numa_policy_init(void);
Paul Jackson74cb2152006-01-08 01:01:56 -0800148extern void mpol_rebind_task(struct task_struct *tsk,
149 const nodemask_t *new);
Paul Jackson42253992006-01-08 01:01:59 -0800150extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
Paul Jacksonc61afb12006-03-24 03:16:08 -0800151extern void mpol_fix_fork_child_flag(struct task_struct *p);
Paul Jackson42253992006-01-08 01:01:59 -0800152
Andi Kleend42c6992005-07-06 19:56:03 +0200153extern struct mempolicy default_policy;
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800154extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
Mel Gorman19770b32008-04-28 02:12:18 -0700155 unsigned long addr, gfp_t gfp_flags,
156 struct mempolicy **mpol, nodemask_t **nodemask);
Christoph Lameterdc85da12006-01-18 17:42:36 -0800157extern unsigned slab_node(struct mempolicy *policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Christoph Lameter2f6726e2006-09-25 23:31:18 -0700159extern enum zone_type policy_zone;
Christoph Lameter4be38e32006-01-06 00:11:17 -0800160
Christoph Lameter2f6726e2006-09-25 23:31:18 -0700161static inline void check_highest_zone(enum zone_type k)
Christoph Lameter4be38e32006-01-06 00:11:17 -0800162{
Mel Gormanb377fd32007-08-22 14:02:05 -0700163 if (k > policy_zone && k != ZONE_MOVABLE)
Christoph Lameter4be38e32006-01-06 00:11:17 -0800164 policy_zone = k;
165}
166
Christoph Lameter39743882006-01-08 01:00:51 -0800167int do_migrate_pages(struct mm_struct *mm,
168 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#else
171
172struct mempolicy {};
173
174static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
175{
176 return 1;
177}
178#define vma_mpol_equal(a,b) 1
179
180#define mpol_set_vma_default(vma) do {} while(0)
181
182static inline void mpol_free(struct mempolicy *p)
183{
184}
185
186static inline void mpol_get(struct mempolicy *pol)
187{
188}
189
190static inline struct mempolicy *mpol_copy(struct mempolicy *old)
191{
192 return NULL;
193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195struct shared_policy {};
196
197static inline int mpol_set_shared_policy(struct shared_policy *info,
198 struct vm_area_struct *vma,
199 struct mempolicy *new)
200{
201 return -EINVAL;
202}
203
Robin Holt7339ff82006-01-14 13:20:48 -0800204static inline void mpol_shared_policy_init(struct shared_policy *info,
205 int policy, nodemask_t *nodes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
207}
208
209static inline void mpol_free_shared_policy(struct shared_policy *p)
210{
211}
212
213static inline struct mempolicy *
214mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
215{
216 return NULL;
217}
218
219#define vma_policy(vma) NULL
220#define vma_set_policy(vma, pol) do {} while(0)
221
222static inline void numa_policy_init(void)
223{
224}
225
226static inline void numa_default_policy(void)
227{
228}
229
Paul Jackson74cb2152006-01-08 01:01:56 -0800230static inline void mpol_rebind_task(struct task_struct *tsk,
Paul Jackson68860ec2005-10-30 15:02:36 -0800231 const nodemask_t *new)
232{
233}
234
Paul Jackson42253992006-01-08 01:01:59 -0800235static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
236{
237}
238
Paul Jacksonc61afb12006-03-24 03:16:08 -0800239static inline void mpol_fix_fork_child_flag(struct task_struct *p)
240{
241}
242
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800243static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
Mel Gorman19770b32008-04-28 02:12:18 -0700244 unsigned long addr, gfp_t gfp_flags,
245 struct mempolicy **mpol, nodemask_t **nodemask)
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800246{
Mel Gorman19770b32008-04-28 02:12:18 -0700247 *mpol = NULL;
248 *nodemask = NULL;
Mel Gorman0e884602008-04-28 02:12:14 -0700249 return node_zonelist(0, gfp_flags);
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800250}
251
Paul Jackson45b07ef2006-01-08 01:00:56 -0800252static inline int do_migrate_pages(struct mm_struct *mm,
253 const nodemask_t *from_nodes,
254 const nodemask_t *to_nodes, int flags)
255{
256 return 0;
257}
258
Christoph Lameter4be38e32006-01-06 00:11:17 -0800259static inline void check_highest_zone(int k)
260{
261}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#endif /* CONFIG_NUMA */
263#endif /* __KERNEL__ */
264
265#endif