blob: 389a06e8ee211cf4b745dd533d04be53402da62c [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 */
David Rientjesa3b51e02008-04-28 02:12:23 -070012enum {
13 MPOL_DEFAULT,
14 MPOL_PREFERRED,
15 MPOL_BIND,
16 MPOL_INTERLEAVE,
17 MPOL_MAX, /* always last member of enum */
18};
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20/* Flags for get_mem_policy */
21#define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
22#define MPOL_F_ADDR (1<<1) /* look up vma using address */
Lee Schermerhorn754af6f2007-10-16 01:24:51 -070023#define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25/* Flags for mbind */
26#define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
Christoph Lameterdc9aa5b2006-01-08 01:00:50 -080027#define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
28#define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
29#define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#ifdef __KERNEL__
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/mmzone.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/slab.h>
35#include <linux/rbtree.h>
36#include <linux/spinlock.h>
Andi Kleendfcd3c02005-10-29 18:15:48 -070037#include <linux/nodemask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39struct vm_area_struct;
Ralf Baechle45b35a52006-06-08 00:43:41 -070040struct mm_struct;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#ifdef CONFIG_NUMA
43
44/*
45 * Describe a memory policy.
46 *
47 * A mempolicy can be either associated with a process or with a VMA.
48 * For VMA related allocations the VMA policy is preferred, otherwise
49 * the process policy is used. Interrupts ignore the memory policy
50 * of the current process.
51 *
52 * Locking policy for interlave:
53 * In process context there is no locking because only the process accesses
54 * its own state. All vma manipulation is somewhat protected by a down_read on
Hugh Dickinsb8072f02005-10-29 18:16:41 -070055 * mmap_sem.
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 *
57 * Freeing policy:
Mel Gorman19770b32008-04-28 02:12:18 -070058 * Mempolicy objects are reference counted. A mempolicy will be freed when
59 * mpol_free() decrements the reference count to zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * Copying policy objects:
Mel Gorman19770b32008-04-28 02:12:18 -070062 * mpol_copy() allocates a new mempolicy and copies the specified mempolicy
63 * to the new storage. The reference count of the new object is initialized
64 * to 1, representing the caller of mpol_copy().
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 */
66struct mempolicy {
67 atomic_t refcnt;
David Rientjesa3b51e02008-04-28 02:12:23 -070068 unsigned short policy; /* See MPOL_* above */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 union {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 short preferred_node; /* preferred */
Mel Gorman19770b32008-04-28 02:12:18 -070071 nodemask_t nodes; /* interleave/bind */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 /* undefined for default */
73 } v;
Paul Jackson74cb2152006-01-08 01:01:56 -080074 nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
77/*
78 * Support for managing mempolicy data objects (clone, copy, destroy)
79 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
80 */
81
82extern void __mpol_free(struct mempolicy *pol);
83static inline void mpol_free(struct mempolicy *pol)
84{
85 if (pol)
86 __mpol_free(pol);
87}
88
89extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
90static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
91{
92 if (pol)
93 pol = __mpol_copy(pol);
94 return pol;
95}
96
97#define vma_policy(vma) ((vma)->vm_policy)
98#define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
99
100static inline void mpol_get(struct mempolicy *pol)
101{
102 if (pol)
103 atomic_inc(&pol->refcnt);
104}
105
106extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
107static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
108{
109 if (a == b)
110 return 1;
111 return __mpol_equal(a, b);
112}
113#define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
114
115/* Could later add inheritance of the process policy here. */
116
117#define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
118
119/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * Tree of shared policies for a shared memory region.
121 * Maintain the policies in a pseudo mm that contains vmas. The vmas
122 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
123 * bytes, so that we can work with shared memory segments bigger than
124 * unsigned long.
125 */
126
127struct sp_node {
128 struct rb_node nd;
129 unsigned long start, end;
130 struct mempolicy *policy;
131};
132
133struct shared_policy {
134 struct rb_root root;
135 spinlock_t lock;
136};
137
David Rientjesa3b51e02008-04-28 02:12:23 -0700138void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
Robin Holt7339ff82006-01-14 13:20:48 -0800139 nodemask_t *nodes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140int mpol_set_shared_policy(struct shared_policy *info,
141 struct vm_area_struct *vma,
142 struct mempolicy *new);
143void mpol_free_shared_policy(struct shared_policy *p);
144struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
145 unsigned long idx);
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147extern void numa_default_policy(void);
148extern void numa_policy_init(void);
Paul Jackson74cb2152006-01-08 01:01:56 -0800149extern void mpol_rebind_task(struct task_struct *tsk,
150 const nodemask_t *new);
Paul Jackson42253992006-01-08 01:01:59 -0800151extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
Paul Jacksonc61afb12006-03-24 03:16:08 -0800152extern void mpol_fix_fork_child_flag(struct task_struct *p);
Paul Jackson42253992006-01-08 01:01:59 -0800153
Andi Kleend42c6992005-07-06 19:56:03 +0200154extern struct mempolicy default_policy;
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800155extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
Mel Gorman19770b32008-04-28 02:12:18 -0700156 unsigned long addr, gfp_t gfp_flags,
157 struct mempolicy **mpol, nodemask_t **nodemask);
Christoph Lameterdc85da12006-01-18 17:42:36 -0800158extern unsigned slab_node(struct mempolicy *policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Christoph Lameter2f6726e2006-09-25 23:31:18 -0700160extern enum zone_type policy_zone;
Christoph Lameter4be38e32006-01-06 00:11:17 -0800161
Christoph Lameter2f6726e2006-09-25 23:31:18 -0700162static inline void check_highest_zone(enum zone_type k)
Christoph Lameter4be38e32006-01-06 00:11:17 -0800163{
Mel Gormanb377fd32007-08-22 14:02:05 -0700164 if (k > policy_zone && k != ZONE_MOVABLE)
Christoph Lameter4be38e32006-01-06 00:11:17 -0800165 policy_zone = k;
166}
167
Christoph Lameter39743882006-01-08 01:00:51 -0800168int do_migrate_pages(struct mm_struct *mm,
169 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#else
172
173struct mempolicy {};
174
175static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
176{
177 return 1;
178}
179#define vma_mpol_equal(a,b) 1
180
181#define mpol_set_vma_default(vma) do {} while(0)
182
183static inline void mpol_free(struct mempolicy *p)
184{
185}
186
187static inline void mpol_get(struct mempolicy *pol)
188{
189}
190
191static inline struct mempolicy *mpol_copy(struct mempolicy *old)
192{
193 return NULL;
194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196struct shared_policy {};
197
198static inline int mpol_set_shared_policy(struct shared_policy *info,
199 struct vm_area_struct *vma,
200 struct mempolicy *new)
201{
202 return -EINVAL;
203}
204
Robin Holt7339ff82006-01-14 13:20:48 -0800205static inline void mpol_shared_policy_init(struct shared_policy *info,
David Rientjesa3b51e02008-04-28 02:12:23 -0700206 unsigned short policy, nodemask_t *nodes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208}
209
210static inline void mpol_free_shared_policy(struct shared_policy *p)
211{
212}
213
214static inline struct mempolicy *
215mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
216{
217 return NULL;
218}
219
220#define vma_policy(vma) NULL
221#define vma_set_policy(vma, pol) do {} while(0)
222
223static inline void numa_policy_init(void)
224{
225}
226
227static inline void numa_default_policy(void)
228{
229}
230
Paul Jackson74cb2152006-01-08 01:01:56 -0800231static inline void mpol_rebind_task(struct task_struct *tsk,
Paul Jackson68860ec2005-10-30 15:02:36 -0800232 const nodemask_t *new)
233{
234}
235
Paul Jackson42253992006-01-08 01:01:59 -0800236static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
237{
238}
239
Paul Jacksonc61afb12006-03-24 03:16:08 -0800240static inline void mpol_fix_fork_child_flag(struct task_struct *p)
241{
242}
243
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800244static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
Mel Gorman19770b32008-04-28 02:12:18 -0700245 unsigned long addr, gfp_t gfp_flags,
246 struct mempolicy **mpol, nodemask_t **nodemask)
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800247{
Mel Gorman19770b32008-04-28 02:12:18 -0700248 *mpol = NULL;
249 *nodemask = NULL;
Mel Gorman0e884602008-04-28 02:12:14 -0700250 return node_zonelist(0, gfp_flags);
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800251}
252
Paul Jackson45b07ef2006-01-08 01:00:56 -0800253static inline int do_migrate_pages(struct mm_struct *mm,
254 const nodemask_t *from_nodes,
255 const nodemask_t *to_nodes, int flags)
256{
257 return 0;
258}
259
Christoph Lameter4be38e32006-01-06 00:11:17 -0800260static inline void check_highest_zone(int k)
261{
262}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif /* CONFIG_NUMA */
264#endif /* __KERNEL__ */
265
266#endif